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 |
alkeshrp
Starting Member
1 Post |
Posted - 2011-11-21 : 05:54:28
|
I have 4 tableTable : studentSTID StName Phone Add1 Add21 Frank 44444 NewYork USA2 Jack 33333 London UK3 Nia 22222 Paris France4 James 45343 Sydney Australia5 Sam 11111 Auckland NewZealandTable : SubjectSdName TeacherName TotalMarksScience Ben 50Computer Mark 30English Larry 50Physics Hilton 30Table : StudentRegisterTrId Stid Date Time1 2 10-03-2011 03:00pm2 1 11-03-2011 03.00pm3 2 12-03-2011 12.00pm4 3 15-03-2011 9:00 am5 2 17-03-2011 12:00 pmTable : StudentsMarkTrid StId SdName Marks1 2 Science 301 2 Computer 152 1 Science 352 1 English 202 1 Physics 253 2 Science 353 2 Computer 254 3 Computer 304 3 Science 255 2 Physics 25I want query that shows this type of tableStid StName Science Computer English Physics Total Per1 Frank 35 20 25 80 50.00%2 Jack 35 25 25 85 53.16% (max out of 2 try )3 Nia 25 30 55 34.38%And so on…I have solution to input like this and can do output like this in visual basic with lots of coding but I want 1 query to get this….. this is simple illustration of my complex database bcoz my subject can change, u can add more subject so I cant use simple 1 table for all.if any one have the solution plz help me…Thanks in advance….. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-21 : 06:28:14
|
[code]SELECT s.STID,s.StName ,[Science], [Computer], [English], [Physics],[Science]+ [Computer]+ [English]+ [Physics] AS Total,([Science]+ [Computer]+ [English]+ [Physics])*100.0/(SELECT SUM(TotalMarks) FROM Subject) AS PerFROM student sinner join StudentsMark smON sm.StId =s.StId PIVOT(SUM(Marks) FOR SdName IN ([Science], [Computer], [English], [Physics] ]))p[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|