SELECT内部INSERT来自多个表的多行

时间:2016-05-05 19:18:51

标签: php mysql sql

这是我的代码:

INSERT INTO CAR_RENTAL.billing
(NO_OF_DAYS,BILL_DATE,DAILY_RENT,ADVANCE,C_NAME,RENTAL_ID,C_CARD,VIN)
VALUES
(7,'2016-01-12',500,1000,
(select c_name from car_rental.customer where c_id=11),
(select rental_id from car_rental.company where rental_id=1),
(select c_card from car_rental.customer where c_id=11),'aud-890'),

(7,'2016-02-12',5000,12000,
(select c_name from car_rental.customer where c_id=12),
(select rental_id from car_rental.company where rental_id=2),
(select c_card from car_rental.customer where c_id=12),'ben-389'),

当我在MYSQL中运行它时,它完全正常。 但是当我尝试在PhPMyAdmin中运行它时,它会出错。

我在这个网站上找到了各种解决方案,但它们都是单个表或单个表。但是没有我想要的类型。

很抱歉,如果它是转贴。

1 个答案:

答案 0 :(得分:0)

只需使用INSERT INTO CAR_RENTAL.billing(NO_OF_DAYS, BILL_DATE, DAILY_RENT, ADVANCE, C_NAME, RENTAL_ID, C_CARD, VIN) select 7, '2016-01-12', 500, 1000, c.c_name, co.rental_id, c.c_card, 'aud-890' from car_rental.customer c cross join car_rental.company co where c.c_id = 11 and co.rental_id = 1;

INSERT INTO CAR_RENTAL.billing(NO_OF_DAYS, BILL_DATE, DAILY_RENT, ADVANCE, C_NAME, RENTAL_ID, C_CARD, VIN)
    select 7, '2016-01-12', 500, 1000, c.c_name, co.rental_id, c.c_card, 
           (case when c.c_id = 11 then 'aud-890' else 'ben-389' end)
    from car_rental.customer c cross join
         car_rental.company co
    where (c.c_id = 11 and co.rental_id = 1) or
          (c.c_id = 12 and co.rental_id = 2)

您可以在一个查询中执行以下操作;

var rectname = new joint.shapes.basic.Rect({
            position: { x: 110, y: y_value },
            size: { width: 450, height: 45 },
            attrs: { 
                rect: { fill: bgcolor2,'stroke-width': 0 },
                text: {
                    text: 'Any text here',
                    fill: 'white'
                }
            }
        });