Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

In --> Group By with Multiple columns...> how it will responds Expand / Collapse
Author
Message
Posted Friday, February 22, 2013 12:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, September 8, 2014 2:11 PM
Points: 8, Visits: 83
can any please help me...!

Thanks & Regards
Prasad Reddy
Post #1423210
Posted Friday, February 22, 2013 12:40 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:51 AM
Points: 12,917, Visits: 32,084
the title of your post "In --> Group By with Multiple columns...> how it will responds " is not enough for us to go by;
can you explain your question better? do you have a coded example that's not working as expected?


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1423221
Posted Friday, February 22, 2013 10:32 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, September 8, 2014 2:11 PM
Points: 8, Visits: 83
query is

select col1, col2, col3.... from table

Group BY Colm, Coln

Here my question is :: while we take 2 or more colmuns in Group By..
Actually how it works
Post #1423320
Posted Sunday, February 24, 2013 9:11 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 5:32 AM
Points: 50, Visits: 75
Below is a basic example for Group By
CREATE TABLE #Studentcourseschedule(
Department int,
Courseid int,
studentid int)
go
insert into #Studentcourseschedule(Department, Courseid,studentid)
values(1,1,1)
,(1,2,1)
,(1,3,1)
,(1,1,5)
,(1,3,6)
,(1,1,7)
,(2,2,1)
,(2,1,2)
,(2,3,2)
go
select department, COUNT(studentid) Studentcount
from #Studentcourseschedule
group by department
order by Department
go
select department, courseid, COUNT(studentid) Studentcount
from #Studentcourseschedule
group by department,courseid
order by Department, Courseid

1st Query Result:
department Studentcount
1 6
2 3
2nd Query Result
department courseid Studentcount
1 1 3
1 2 1
1 3 2
2 1 1
2 2 1
2 3 1

In the first query the grouping is done only on Department, so it checks the no of students in each of the Department available in the table which is 1 and 2 in example
When we add another group by column on courseid, now it looks for the each course available under each department and displays count of the student in that department and course.
Post #1423467
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse