111,126
社区成员
发帖
与我相关
我的任务
分享
--先创建个表
create table test
(
name varchar(10),
score int
)
go
insert into test (name,score) values ('甲',95)
insert into test (name,score) values ('乙',45)
insert into test (name,score) values ('丙',86)
insert into test (name,score) values ('丁',77)
--用下面的SQL语句 试试看
select count(name) as 总人数,(select count(*) from test where score>85) as 优秀人数 ,
(select count(*) from test where score<85 and score>=75) as 良的人数,
(select count(*) from test where score<60 ) as 差的人数 from test
--接着就是绑定了
--呵呵献丑了
DataRow[] you = dt.Select("语文 >= 85") ?? new DataRow[0];
DataRow[] liang = dt.Select("语文 < 85 and 语文 >=75") ?? new DataRow[0];
DataRow[] cha = dt.Select("语文 < 75") ?? new DataRow[0];
DataTable dtSummary = new DataTable();
dtSummary.Columns.Add("总人数");
dtSummary.Columns.Add("优");
dtSummary.Columns.Add("良");
dtSummary.Columns.Add("差");
dtSummary.Rows.Add(dt.Rows.Count, you.Length, liang.Length, cha.Length);
dataGridView1.DataSource = dtSummary;
create proc GetInfo
(
@AllPeople int , --所有的人数
@Actor int ,--成绩为优的
@Fine int ,--成绩为良的
@Bad int --成绩为差的
)
as
set @AllPeople=(select count(*) from 成绩表)
set @Actor=(select count(*) from 成绩表 where 成绩>=85) --也就是为优秀的
set @Fine=(select count(*) from 成绩表 where 成绩<85 and 成绩 >=75) --良
set @Bad=(select count(*) from 成绩表 where 成绩<60) --差
--创建临时表存储信息
create table #成绩汇总
(
AllPeople int,
Actor int,
Fine int,
Bad int
)
--插入信息
insert into #成绩汇总表(AllPeople,Actor,Fine,Bad) values(@allPeople,@Actor,@Fine,@Bad)
--查找信息
select * from #成绩汇总表
create proc GetInfo
(
@AllPeople int output, --所有的人数
@Actor int output,--成绩为优的
@Fine int output,--成绩为良的
@Bad int output--成绩为差的
)
as
set @AllPeople=(select count(*) from 成绩表)
set @Actor=(select count(*) from 成绩表 where 成绩>=85) --也就是为优秀的
set @Fine=(select count(*) from 成绩表 where 成绩<85 and 成绩 >=75) --良
set @Bad=(select count(*) from 成绩表 where 成绩<60) --差
--创建临时表存储信息
create table #成绩汇总
(
AllPeople int,
Actor int,
Fine int,
Bad int
)
--插入信息
insert into #成绩汇总表(AllPeople,Actor,Fine,Bad) values(@allPeople,@Actor,@Fine,@Bad)
--查找信息
select * from #成绩汇总表