Senthilkumar Posted February 29 Share Posted February 29 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 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 29 Share Posted February 29 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 ='') Quote Link to comment Share on other sites More sharing options...
Senthilkumar Posted February 29 Author Share Posted February 29 Thanks for your reply. I will check it and update u Quote Link to comment Share on other sites More sharing options...
Barand Posted February 29 Share Posted February 29 NOTE: I missed out a "NOT" - I edited my reply to correct. Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted February 29 Solution Share Posted February 29 OR you can use the complement - select count(*) as CustomerActual, Month from sbms.customerdata WHERE EmpID='83201858' AND (VisitType = 'No Due' OR VisitDate !='') group by Month Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.