我正在尝试创建一个显示所选月份数据的报告。我的MySQL查询如下所示:
SELECT Count(images.image_url) AS num_images,
( Day(Date(timestamp)) ) AS tday,
Month(Date(transactions.timestamp)) AS month,
transactions.sr_no
FROM bni_pixcapp_client_details AS transactions
INNER JOIN bni_pixcapp_image_urls AS images
ON images.sr_no = transactions.sr_no
WHERE Month(Date(transactions.timestamp)) = 4
AND Year(Date(transactions.timestamp)) = 2014
AND transactions.payment_status = 'Manually created'
OR payment_status = 'Completed'
GROUP BY Day(Date(timestamp))
查询看起来很好吗?
但接下来是结果
如何摆脱3月份无关的进入?我尝试使用HAVING代替WHERE,但无法让查询运行。
答案 0 :(得分:1)
试试这个,我认为你的条件应该在()。
SELECT Count(images.image_url) AS num_images,
( Day(Date(timestamp)) ) AS tday,
Month(Date(transactions.timestamp)) AS month,
transactions.sr_no
FROM bni_pixcapp_client_details AS transactions
INNER JOIN bni_pixcapp_image_urls AS images
ON images.sr_no = transactions.sr_no
WHERE Month(Date(transactions.timestamp)) = 4
AND Year(Date(transactions.timestamp)) = 2014
AND (
transactions.payment_status = 'Manually created'
OR
payment_status = 'Completed'
)
GROUP BY Day(Date(timestamp))
答案 1 :(得分:1)
Try your where clause like below
WHERE (Month(Date(transactions.timestamp)) = 4
AND Year(Date(transactions.timestamp)) = 2014 )
AND (transactions.payment_status = 'Manually created'
OR payment_status = 'Completed' )