Jump to content

Row count based on the two condition


Go to solution Solved by mac_gyver,

Recommended Posts

Dear Team,

 

I am writing a query to count rows based on the two conditions. But I am not getting proper output.

My table is 

image.png.40a00542671cdfb987563096a25c6d08.png

my query is 

select count(*) as CustomerActual, Month from sbms.customerdata WHERE EmpID='83201858' AND  NOT(VisitType = 'No Due' AND VisitDate ='')  group by Month

My condition is when the date is empty it should not count that row. But if the visit type is 'No due' it should count the row.

for example, in 2024-04  month the actual row is 5. As per the above condition, the row count is 4. Because the visit type is No due on ID 1713 and ID 1712 the date is blank. so the count is 4. 

Instead of No due, if any other is in the visit type column on id 1713, then it should not count. the total count should show on 3. 

Can anyone help me with how to do this?

Link to comment
https://forums.phpfreaks.com/topic/318537-row-count-based-on-the-two-condition/
Share on other sites

24 minutes ago, Senthilkumar said:

My condition is when the date is empty it should not count that row. But if the visit type is 'No due' it should count the row.

try

WHERE EmpID='83201858' AND NOT (VisitType <> 'No Due' AND VisitDate ='')

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.