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.
Author |
Topic |
gimmely
Starting Member
5 Posts |
Posted - 2007-04-27 : 10:21:45
|
I'm not trained in SQL, so I got stuck with the following issue. Hopefully, there's an easy query for or solution to this seemingly-so-simple issue.My table has two columns, name and value. I want to get a result formatted as below:Name# of Value1 ... # of ValueN Totalname1 c11 c1N c11+...+c1N...nameN cN1 cNN cN1+...+cNNTotal c11+...cN1 c1N+...+cNN (all)I don't know if I have to define cube to accomplish this. Thanks and sorry for the final display of the format as I don't know how to put Tab in. |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2007-04-27 : 11:06:27
|
Format = Front end issue. In other words, where are you going to show this data? Use THAT tool to format the data in the desired way.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
gimmely
Starting Member
5 Posts |
Posted - 2007-04-27 : 11:35:55
|
I agree to your definition of "format" and am sorry I didn't make it clear enough. What I am looking for is to do it in SQL, if possible.Thanks. |
 |
|
gimmely
Starting Member
5 Posts |
Posted - 2007-04-27 : 12:01:39
|
Please discard the question, as I've figured out how to create everything except for the Total line at the bottom, which should be easier. Sample code is below:select name, sum(total1) as '# of Value1', ..., sum(totalN) as '# of ValueN', sum(total1) + ... + sum(totalN) as 'Total' from (select name, case when (value = value1) then count(*) end as 'total1', ... case when (value = valueN) then count(*) end as 'totalN' from [table name] group by name, value) agroup by name |
 |
|
|
|
|
|
|