douhan6738 2015-12-08 17:50
浏览 37

GROUP BY查询仅显示与html表中的日期关联的一行

I tried a query to show items of same date in my table with different rows but date should be displayed only once. Something like this.

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

I tried the following query. It just returns me only one row for each date.

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

Any suggestions please. How can i display like this in my html table.

  • 写回答

1条回答 默认 最新

  • doucai5315 2015-12-08 17:58
    关注

    Group by looks for an aggregate function i.e. sum('field_name'). You will need to get the distinct values for the order.date then subquery (not sure the parentheses are in the right spot).

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程