0

次の手順を使用して合計を取得presentsabsents、ピボットクエリを使用しています.... And And thenSUMしたいPresents[P]Absents[A]calculate percentage

ALTER PROCEDURE [dbo].[GetAttendence](@Course_Id varchar(30), @Semester varchar(10))

AS
   SELECT DISTINCT Enroll_Number, Course_Id, Semester, Isnull([P],0) 
                                           As Presents, Isnull([A],0) As Absents

    FROM (SELECT Enroll_Number, Course_Id, Semester, Flag from Attendence ) ps
    pivot(Count(Flag) for Flag in ([P],[A])) as pvt 

    WHERE Course_Id = @Course_Id and Semester = @Semester

これはForula実装することです....

合計 = プレゼント + 不在

パーセンテージ = ((プレゼント / 合計) * 100)

4

1 に答える 1

0

これを試して:

select Enroll_Number,
       Course_Id,
       Semester,
       P as Presents,
       A as Absents,
       P+A as SumPA,
       1.0*P/(P+A)*100 as Percentage
from
  (
    select Enroll_Number, Course_Id, Semester, Flag
    from Attendence
    where Course_Id = @Course_Id and 
          Semester = @Semester
  ) ps
pivot
  (
    count(Flag) for Flag in ([P],[A])
  ) as pvt 
于 2012-06-15T07:27:17.620 に答える