Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Novice SQL needs syntax help

Author  Topic 

rvignato
Starting Member

2 Posts

Posted - 2008-10-25 : 20:15:06
I'm a C# asp.net guy. (not as smart as you SQL people)

Can someone help me with a query that would allow me to generate this?

Total Sales Orders - 6
* Nike - 4
* Adidas - 3
* Fruit of the Loom - 5

If I can get the data, even in aliases, I can grab it and mark it up.

Thanks for reading all those SQL books for me :>

Robert

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-26 : 01:03:41
assuming the field containing Nike.Adidas,... is called Brand, it will be like below



SELECT Brand,TotalCount
FROM
(
SELECT 'Total' AS Brand,COUNT(*) AS TotalCount,0 AS OrderVal
FROM YourTable
UNION ALL
SELECT Brand,COUNT(*) AS TotalCount,1
FROM YourTable
GROUP BY Brand
)t
Order BY OrderVal
Go to Top of Page

rvignato
Starting Member

2 Posts

Posted - 2008-10-27 : 16:42:55
Thanks!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-27 : 17:55:06
What happened to WITH ROLLUP?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -