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
 General SQL Server Forums
 New to SQL Server Programming
 Count and Group

Author  Topic 

vadz82
Starting Member

1 Post

Posted - 2011-10-07 : 11:01:25
Hi there! am novice to sql and i want to count and group my data like this

value1 val2 value3 value4

delhi 43 india SA
madras 42 india SA
london 55 england EU
toronto 68 canada NA
tokyo 22 japan SEA
kyoto 23 japan SEA
ontario 69 canada NA
california 78 USA NA
texas 70 USA NA
carolina 72 USA MA
maryland 76 USA NA
florida 72 USA MA
Wales 55 england EU
Stakholom 50 sweden EU
switzerland 51 switzerland EU
Heidelberg 53 germany EU

into this;
value 4 value 3 val2
EU
england 2
germany 1
sweden 1
switzerland 1

MA
USA 2
NA
canada 2
USA 3

SA
india 2

SEA
japan 2

For example i will use val2 as my reference.How am i going to do this? Thanks!

Cindyaz
Yak Posting Veteran

73 Posts

Posted - 2011-10-07 : 11:12:19
difficult to post a definitive reply. Please give your DDL statements (create table statements), along with sample data (preferably using insert statement) and expected output. That will help us to help you.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-07 : 12:29:55
looks more of a presentation issue. is it for reporting need? if yes, this format can be very easily generated in reporting tools using grouping levels.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

paultech
Yak Posting Veteran

79 Posts

Posted - 2011-10-07 : 14:15:53
Hello ,i tried to understand you ,But difficult so make more clarifications of your requirements, But i agree with visakh16 ,That if you want specific format to display your data ,So you need to use reporting tools as Crystal report
thanks

Go to Top of Page
   

- Advertisement -