|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Question concerning Aggregation.
I would like to find out from my orders table, which productID occurrs the most. I do not want to list every single ProductID, and the number of times it occurs in my order table. I only want to list 1 row The Number of times The productID that was purchase most often was purchased and which product it it was. Currently I have this.<br><br>SELECT Count(ProductID)<br> FROM Orders<br> GROUP BY ProductID<br> ORDER BY ProductID desc;<br><br>This is ok, but I only want to display the ProductID that occurs the most. I don't want every productID, and how many times it was purchased, only the one that was purchased the most.<br><br>Any help would be greatly appreciated.
|
|
#2
|
|||
|
|||
|
You try in this way ...<br><br>select T1.s, t1.PurchaseID from <br> ( select count(*) s , T2.PurchaseID from order T2 <br> group by t2.PurchaseID<br> ) as T1<br>where T1.s = ( select max(T1.s) from ( select count(*) s from Order T2 <br> group by t2.PurchaseID) )
|
|
#3
|
|||
|
|||
|
just read PurchaseId as ProductID and order as orders table. ..<br><br>Good Luck ...<br> ravie
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > SQL Question concerning Aggregation. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|