Author |
Topic |
Mohamed Faisal
Yak Posting Veteran
51 Posts |
Posted - 2013-08-11 : 03:42:42
|
I have 3 tables:Student table(StudentNumber,Name,Contact,Address,DateOfBirth,YearEnrolled,Year Of Study)Absence table(SubjectCode,StudentNumber, DateOfAbsence)Subject table(SubjectCode, Subject Name,Description)I would need to display StudentNumber, Name, SubjectCode and the pecentatage of Date of Absence)taking that there are 10 lessonHow can i disply the above. |
|
jethrow
Starting Member
37 Posts |
Posted - 2013-08-11 : 04:23:20
|
[code]Declare @NumOfLessions float = 10 --specified in the OPDeclare @Student table (StudentNumber int, Name varchar(32))Insert Into @Student values (1, 'Joe'), (2, 'Kelly'), (3, 'Casey');Declare @Absence table (SubjectCode char(3), StudentNumber int, DateOfAbsence date);Insert Into @Absence values ('mat', 2, '2013-01-13'), ('mat', 1, '2013-01-16'), ('mat', 1, '2013-01-25'), ('ped', 3, '2013-01-15'), ('ped', 3, '2013-01-20');Select a.StudentNumber, Name, SubjectCode, Cast(Count(DateOfAbsence)/@NumOfLessions*100 as VarChar(5))+'%' PercentAbsentFrom @Absence aLeft Join @Student s On a.StudentNumber=s.StudentNumberGroup By a.StudentNumber, Name, SubjectCode;[/code]Microsoft SQL Server Noobie |
 |
|
Mohamed Faisal
Yak Posting Veteran
51 Posts |
Posted - 2013-08-11 : 06:19:38
|
for my table there is no NumOfLesson. All i know it has to calculating using:((10*count(*))*100/10)But not sure how to use it |
 |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-11 : 11:02:48
|
where (which table and column name) do you store the number of lessons to get the count from. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-08-11 : 15:02:46
|
You are probably getting integer division.Try ((10E*count(*))*100/10) Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
|
|
|