I'm trying to create a report that shows data for the selected month. My MySQL query looks like this:
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))
Query looks fine right?
But then here are the results
How do I get rid of the extraneous entry for March? I tried using HAVING instead of WHERE but couldn't get the query to run.
Try this, I think your Or condition should be in ().
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))
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' )