[Solved] SQL Query to Count total rows grouping different columns


There are 3 quite different methods needed to arrive at the counts, so I have used 3 separate sub-queries. see this working at sqlfiddle (but not on MS SQL Server) here: http://sqlfiddle.com/#!5/9df16/1

Result:

| Total_Count | Repeat_Return | Same_Symptom_Return |
|-------------|---------------|---------------------|
|           6 |             2 |                   1 |

Query:

select
    (select count(distinct SN + RMA + SYMPTOM) from table1) as Total_Count
,   (select count(*) from(
         SELECT  SN
         FROM table1
         Group by SN
         having count(distinct Date_Returned) > 1)
     ) as Repeat_Return
,   (select count(*) from(
         SELECT  SYMPTOM  
         FROM table1
         Group by SYMPTOM  
         having count(*)/3 > 1)
     ) as Same_Symptom_Return

note: you should include “sql server” as a tag on your question (well I presum it is that because of the [dbo].[test]

solved SQL Query to Count total rows grouping different columns