skip to Main Content

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

Answers


  1. Count the distinct order_ids with status = 1:

    select count(distinct order_id) total_count
    from tablename
    where status = 1
    
    Login or Signup to reply.
  2. You can use COUNT(DISTINCT <column>). For example:

    select count(distinct order_id) from t where status = 1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search