December 15, 2010 at 10:31 am
how do I find the max # of rows within a table based on 2 fields?
I want to return the max (count) of rows where column A & column B are the same value.
December 15, 2010 at 10:36 am
Select columna , count(columna) as Counted
From sometable
Where columna=columnb
group by columna
order by counted desc
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
December 15, 2010 at 12:57 pm
sorry, I did not explain it very well
..... lets say column a has value 20 and columnb has value 30 many time within a table(but I don't know how many times they are repeated ...I want to know the max count for the combination of both fields where columna & columnb. = 20,30 ?
December 15, 2010 at 1:05 pm
so you want a sum of columna and columnb?
Could you provide sample data and expected results? From there we can create a query.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
December 15, 2010 at 1:09 pm
Try this out....
select columna, columnb, count(*) from Table
group by columna, columnb
December 15, 2010 at 1:13 pm
kevin4u06 (12/15/2010)
Try this out....select columna, columnb, count(*) from Table
group by columna, columnb
December 15, 2010 at 2:46 pm
Thanks.....this works great...I just need to do a join to another table to filter the rows I really wanted.
Thanks again... you rock!
December 15, 2010 at 2:48 pm
Thanks..... I got it from the reply below and adding a join to filter what I really wanted.
Thanks again!
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply