How to select the same field twice with different conditions and display results as separate fields

后端 未结 3 590
渐次进展
渐次进展 2021-01-24 23:56

I want to create a Table Adapter in C# as follows.

I wish to use same filed in a table twice with different conditions, and it must be shown as two diff

3条回答
  •  不知归路
    2021-01-25 00:23

     SELECT A.StudentID, A.Studname, A.StudSex, A.StudCourse, 
    SUM(CASE WHEN A.AttendStatus = 'Present' THEN 1 ELSE 0 END) AS TotalPresent,
    SUM(CASE WHEN A.AttendStatus = 'Absent' THEN 1 ELSE 0 END) AS TotalAbsent
    FROM AttendanceReg A 
    INNER JOIN LocalTable L ON A.StudCourse = L.AttendCourse AND DatePart('M', A.DateOfAttendance) = L.AttentMonth)
    
    GROUP BY A.StudentID, A.Studname, A.StudSex, A.StudCourse
    

提交回复
热议问题