按月和年组mysql查询

时间:2016-05-10 23:46:13

标签: mysql sql date

按照customer_gender,商店,月份和年份查找2012年之前产品'Beta600'的所有帐户借记卡总额

我运行此查询但我无法得到我想要的结果:

SELECT customer_gender, product_code, month(transactions.trn_date),
year(transactions.trn_date), COUNT(trn_amount)
FROM customers, products, transactions, accounts
WHERE customer.customerid = accounts.customer_id 
AND transactions.account_id = accounts.account_id
AND accounts.product_code = products.product_code AND products.poduct_name = 'Beta600'
AND transactions.trn_date < '1/1/2012' AND accounts.account_currency = 'EUR'
GROUP BY customer_gender, product_code, month(transactions.trn_date),
year(transactions.trn_date)

0 个答案:

没有答案