Good morning.I have the following sample data (T_MyTable):RowID ColName Flag1 Flag2-------------------------------1 Data A 0 12 Data B 0 13 Data C 1 14 Data D 1 0
I am selecting data from a bunch of tables, but need to really only display the data from the sample table data above. Right now, the only way I can do what I want is with the following SQL:SELECT ColName, (SELECT COUNT(RowID) FROM T_MyTable WHERE Flag1 = 0) AS Flag1Count, (SELECT COUNT(RowID) FROM T_MyTable WHERE Flag2 = 0) AS Flag2CountFROM T_MyTable
My question is if there is a way to get rid of the sub selects to return the count data another way. I originally thought of using the OVER PARTITION BY clause, but that will not work since I have the WHERE clause on the Flag1 and Flag2 fields to get the counts of each.I am just trying to make this as clean with as little look ups as possible. I will have a few hundred thousand to over a million rows, so the SQL above is going to slow over time.Thanks in advance for the help. Please let me know if I missed anything to help answer.Dennis