从上述ERD,我试图选择2月,9月和12月销售的产品总数及其描述。
这是我的发票表的摘要:
INV_NUMBER CUS_CODE INV_DATE
1001 10014 2016-01-16 00:00:00
1002 10011 2016-01-16 00:00:00
1003 10012 2016-01-16 00:00:00
我的SQL查询:
SELECT P_DESCRIPT AS Product, SUM(P_CODE) AS 'Units Sold'
FROM product
JOIN invoice
WHERE INV_DATE LIKE (DATE_FORMAT("2017-01%-15", "%Y", "%m" )
OR DATE_FORMAT("2017-06%-15", "%Y", "%m" )
OR DATE_FORMAT("2017-07%-15", "%Y", "%m" ))
GROUP BY P_DESCRIPT;
答案 0 :(得分:3)