不唯一的表/别名加入查询

时间:2016-03-23 03:25:36

标签: mysql join

我一直在获取不唯一的表/别名:sqlfiddle中的'Donut_Order'错误 我已经google了一下,在stackoverflow上查看了许多相同的问题,并意识到它与别名有关但我无法绕过它。谁能解释我在这里做错了什么?

#container-div {
    position: relative;
    min-height:50px;
}
#buttons-div {
    position:absolute;
    bottom: 0px;
    right: 0px;
    width:60%;

}

li{
  float:left;
  padding: 10px;
  list-style:none;
}

2 个答案:

答案 0 :(得分:0)

呃,试试这个:

SELECT date_of_order, qodio.donut_order_id, c.customer_id, first_name, last_name, street_address, apt_number, city, st, zip_code, home_phone, mobile_phone, other_phone, qty_of_donuts, d.donut_id, name, description, unit_price, unit_price * qty_of_donuts AS line_total, sum(unit_price * qty_of_donuts) AS sub_total, tax, sum(unit_price * qty_of_donuts) * 1.1 AS total, handling_notes
FROM Customer c 
JOIN Donut_Order do ON c.customer_id = do.customer_id
JOIN Qty_Of_Donuts_In_Order qodio ON do.donut_order_id = qodio.donut_order_id
JOIN Donut d ON qodio.donut_id = d.donut_id;

答案 1 :(得分:0)

试试这个:

SELECT date_of_order, Qty_Of_Donuts_In_Order.donut_order_id, Customer.customer_id,
first_name, last_name, street_address, apt_number, city, st, zip_code, home_phone, mobile_phone, other_phone,
qty_of_donuts, Donut.donut_id,
name, description, unit_price,
unit_price * qty_of_donuts AS line_total,
sum(unit_price * qty_of_donuts) AS sub_total,
tax, sum(unit_price * qty_of_donuts) * 1.1 AS total, 
handling_notes
FROM Customer 
    JOIN Donut_Order ON Customer.customer_id = Donut_Order.customer_id,
    JOIN Qty_Of_Donuts_In_Order ON Donut_Order.donut_order_id = Qty_Of_Donuts_In_Order.donut_order_id,
    JOIN Donut ON Qty_Of_Donuts_In_Order.donut_id = Donut.donut_id;