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 |
LacOniC
Starting Member
29 Posts |
Posted - 2014-12-04 : 04:06:35
|
Hi. I need a query that share students to classes. For example there are 15 Boys, 25 Girls and 4 classes. Query should share all sexes -if possible- equal to classes. In this example i need something like that:Class 1: 4 Boys 6 GirlsClass 2: 4 Boys 6 GirlsClass 3: 4 Boys 6 GirlsClass 4: 3 Boys 7 Girlsor Class 1: 4 Boys 7 GirlsClass 2: 4 Boys 6 GirlsClass 3: 4 Boys 6 GirlsClass 4: 3 Boys 6 GirlsThnaks in advance. |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-04 : 08:51:59
|
This is clearly homework. You need to take a crack at it yourself first. Remember your lectures on SELECT and see what you come up with. |
|
|
viggneshwar
Yak Posting Veteran
86 Posts |
Posted - 2014-12-04 : 09:33:14
|
May be this would be helpfulSELECT classname + ': ' + CONVERT(VARCHAR(3),MAX(CASE WHEN sex='Male' THEN 1 ELSE 0 END)) + ' Boys' + CONVERT(VARCHAR(3),MAX(CASE WHEN sex='Female' THEN 1 ELSE 0 END)) + ' Girls'FROM tablenameGROUP BY classnameRegardsViggneshwar A |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-04 : 09:46:46
|
quote: Originally posted by viggneshwar May be this would be helpful
I'm sure it is, but then the OP won't learn anything from doing their homework, will they? |
|
|
viggneshwar
Yak Posting Veteran
86 Posts |
Posted - 2014-12-12 : 02:40:16
|
Yeah you are right. If it is urgency then the solution is better as of now. Surely have to learn by considering this as an example.RegardsViggneshwar A |
|
|
|
|
|