1

Input table (named ruchin)

id     comment           order_id          deleted_at
1        abc               1234              NULL
2        abcd              1234              TimeStamp
3        xyz               1234              NULL
4        pqr               1234              TimeStamp
5        as                4567               NULL
6        lo                4567               NULL

and I want output as

order_id        count(deleted_at==Timestamp)    count(deleted_at==NULL)
1234                   2                                 2
4567                   0                                  2

and I want this to be in single query.How can I do this???

1 Answer 1

3

You can use the function count() for that, since it doesn't count NULL values.

Here is the query:

SELECT order_id, 
       count(deleted_at) as 'del is not null',
       count(order_id) - count(deleted_at) as 'del is NULL' 
FROM ruchin 
GROUP BY order_id
Sign up to request clarification or add additional context in comments.

1 Comment

Here NULL is the parameter,it doesn't means actual NULL,consider NULL as variable x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.