私はプロジェクトを持っています。目的は、画像に示すように結果を分析することです:
ただし、ここの画像では、私のテーブルは次のようになっています。
ここで、この質問のタイトルを使用して検索し、画像 2 のテーブルを使用して画像 1 に示した結果を達成する方法を確認しました。
CREATE proc [dbo].[getScoreClassificationbySchools]
@NameofSchool nvarchar(31), @levelName nvarchar(5)
as
Begin
create table #A(LevelNames varchar(50), SchoolSubject varchar (50))
create table #B(LevelNames varchar(50), TotalNostudent int, SchoolSubjectt varchar (50))
create table #C(LevelNames varchar(50), ScoreClassDistinction varchar (10), SchoolSubject varchar (50))
create table #D(LevelNames varchar(50), ScoreClassCredit varchar (10), SchoolSubject varchar (50))
create table #E(LevelNames varchar(50), ScoreClassPass varchar (10), SchoolSubject varchar (50))
create table #F(LevelNames varchar(50), ScoreClassFail varchar (10), SchoolSubject varchar (50))
insert into #A(LevelNames, SchoolSubject)
select distinct LevelName, Subject from tb_schlist where @levelName =LevelName AND @NameofSchool = SchoolName
insert into #B(LevelNames, TotalNostudent,SchoolSubjectt)
select distinct LevelName, count (LevelName) as TotalNoOfStudent, Subject from tb_schlist where @levelName =LevelName AND @NameofSchool = SchoolName
insert into #C(LevelNames, ScoreClassDistinction, SchoolSubject)
select distinct LevelName, Grades, Subject from tb_schlist where @levelName =LevelName and @NameofSchool = SchoolName and Grades='A1'
insert into #D(LevelNames, ScoreClassCredit, SchoolSubject)
select distinct LevelName, Grades, Subject from tb_schlist where @levelName =LevelName and @NameofSchool = SchoolName and Grades='B2'
insert into #E(LevelNames, ScoreClassPass, SchoolSubject)
select distinct LevelName, Grades, Subject from tb_schlist where @levelName =LevelName and @NameofSchool = SchoolName and Grades='B3'
insert into #F(LevelNames, ScoreClassFail, SchoolSubject)
select distinct LevelName, Grades, Subject from tb_schlist where @levelName =LevelName and @NameofSchool = SchoolName and Grades='C4'
SELECT t1.lnames , t2.SchoolSubject, t3.ScoreClassDistinction, t4.ScoreClassCredit, t5.ScoreClassPass, t6.ScoreClassFail from #A t1 join #B t2 on t1.LevelNameS = t2.LevelNames join #C t3 join #D t4 on t3.LevelNames = t4.LevelNames join #E t5 join #F t6 on t5.LevelNames = t6.LevelNames