I have attached order table, Please find below. I need a count value 4, can you help me make a SQL query
Note : status = 1 and order_id should count only one time if order_id available with more than one row
2
Count the distinct order_ids with status = 1:
order_id
status = 1
select count(distinct order_id) total_count from tablename where status = 1
You can use COUNT(DISTINCT <column>). For example:
COUNT(DISTINCT <column>)
select count(distinct order_id) from t where status = 1
Click here to cancel reply.
2
Answers
Count the distinct
order_id
s withstatus = 1
:You can use
COUNT(DISTINCT <column>)
. For example: