我尝试了一个查询,在我的表中显示具有不同行的相同日期的项目,但日期应该只显示一次。这样的事情。
Date: 15-09-2015
ItemId:1 quantity:6 size:XL
ItemId:1 quantity:4 size:Small
ItemId:2 quantity:6 size:XL
Date: 16-09-2015
ItemId:3 quantity:9 size:XL
ItemId:1 quantity:4 size:Small
ItemId:2 quantity:6 size:XL
我尝试了以下查询。它只为每个日期返回一行。
SELECT orders.date, order_detail.quantity, order_detail.price, order_detail.color, order_detail.size, customers.name, products.product_name, products.product_image FROM order_detail JOIN orders ON orders.serial=order_detail.orderid JOIN customers ON customers.serial=orders.customerid JOIN products ON products.productid=order_detail.productid WHERE customers.email='abc@yahoo.com' GROUP BY orders.date ORDER BY orders.date
请提出任何建议。我怎么能在我的html表格中显示这样的内容。
答案 0 :(得分:0)
分组查找聚合函数,即sum(' field_name')。您需要获取order.date然后子查询的不同值(不确定括号是否在正确的位置)。
SELECT DISTINCT orders.date, (SELECT order_detail.quantity, order_detail.price, order_detail.color, order_detail.size, customers.name, products.product_name, products.product_image FROM order_detail JOIN orders ON orders.serial=order_detail.orderid JOIN customers ON customers.serial=orders.customerid JOIN products ON products.productid=order_detail.productid WHERE customers.email='abc@yahoo.com') GROUP BY orders.date ORDER BY orders.date