select A.班级号,未缴费人数=count(*) from 班级表 A inner join 学生表 B on A.班级号=B.班级号 where A.专业号='2' and B.缴费否='0' group by A.班级号
create table xsb (xh nvarchar(10),bjh nvarchar(10), bj bit) go create table zyb (zyh int) go create table bjb(bjh nvarchar(10),zyh int,rs int) go insert zyb select 1 insert zyb select 2 go insert bjb select 'A001', 1, 50 insert bjb select 'A002', 1, 52 insert bjb select 'B001', 2, 56 go insert xsb select 'S001', 'A001', 1 insert xsb select 'S002', 'A001', 0 insert xsb select 'S003', 'A002', 0 insert xsb select 'S004', 'B001', 1 insert xsb select 'S005', 'B001', 0 go select bjb.zyh as 专业号,xsb.bj as 未缴费人数 from bjb ,xsb where bjb.bjh=xsb.bjh and bjb.zyh=zyb.zyh
--楼主的意思,应该用存储过程比较合适(即"专业号"作为变量来调用,结果返回"未缴费人数") create proc p(@zyh varchar(20)) as select 未缴费人数=sum(case 缴费否 when 'NO' then 1 else 0 end) from 学生表 a,班级表 b where a.班级号=b.班级号 and b.专业号=@zyh go exec p '计算机应用'
declare @id varchar(50)select 班级号,count(缴费否) as 未缴费人数 from 学生表 a,班级表 b,专业表 c where a.班级号=b.班级表 and b.专业号=c.专业号 and 专业号=@id and 缴费否=0 group by 班级号
--上面少写个c. declare @id varchar(50)select 班级号,count(缴费否) as 未缴费人数 from 学生表 a,班级表 b,专业表 c where a.班级号=b.班级表 and b.专业号=c.专业号 and c.专业号=@id and 缴费否=0 group by 班级号
FROM 学生表
WHERE (缴费否 = 0) AND (班级号 IN
(SELECT 班级号
FROM [班级表]
WHERE 专业号 = '001'))
GROUP BY 班级号
from 班级表 A
inner join 学生表 B on A.班级号=B.班级号
where A.专业号='输入的专业号' and B.缴费否='否'
group by A.班级号
create table 专业表(专业号 int)
insert 专业表 select 1
insert 专业表 select 2create table 班级表(班级号 nvarchar(10), 专业号 int, 人数 int)
insert 班级表 select 'A001', 1, 50
insert 班级表 select 'A002', 1, 52
insert 班级表 select 'B001', 2, 56create table 学生表(学号 nvarchar(10),班级号 nvarchar(10), 缴费否 bit)
insert 学生表 select 'S001', 'A001', 1
insert 学生表 select 'S002', 'A001', 0
insert 学生表 select 'S003', 'A002', 0
insert 学生表 select 'S004', 'B001', 1
insert 学生表 select 'S005', 'B001', 0select A.班级号,未缴费人数=count(*)
from 班级表 A
inner join 学生表 B on A.班级号=B.班级号
where A.专业号='2' and B.缴费否='0'
group by A.班级号--result
班级号 未缴费人数
---------- -----------
B001 1(1 row(s) affected)
from 班级表 A
inner join 学生表 B on A.班级号=B.班级号
where A.专业号='2' and B.缴费否='0'
group by A.班级号
go
create table zyb (zyh int)
go
create table bjb(bjh nvarchar(10),zyh int,rs int)
go
insert zyb select 1
insert zyb select 2
go
insert bjb select 'A001', 1, 50
insert bjb select 'A002', 1, 52
insert bjb select 'B001', 2, 56
go
insert xsb select 'S001', 'A001', 1
insert xsb select 'S002', 'A001', 0
insert xsb select 'S003', 'A002', 0
insert xsb select 'S004', 'B001', 1
insert xsb select 'S005', 'B001', 0
go
select bjb.zyh as 专业号,xsb.bj as 未缴费人数 from bjb ,xsb where bjb.bjh=xsb.bjh and bjb.zyh=zyb.zyh
create proc p(@zyh varchar(20))
as
select 未缴费人数=sum(case 缴费否 when 'NO' then 1 else 0 end) from 学生表 a,班级表 b
where a.班级号=b.班级号 and b.专业号=@zyh
go
exec p '计算机应用'
declare @id varchar(50)select 班级号,count(缴费否) as 未缴费人数
from 学生表 a,班级表 b,专业表 c
where a.班级号=b.班级表 and b.专业号=c.专业号
and 专业号=@id and 缴费否=0
group by 班级号
declare @id varchar(50)select 班级号,count(缴费否) as 未缴费人数
from 学生表 a,班级表 b,专业表 c
where a.班级号=b.班级表 and b.专业号=c.专业号
and c.专业号=@id and 缴费否=0
group by 班级号
输入学院号,
输出专业号,未缴费人数我想再创建一个存储过程,然后调用你写的那个存储过程,我该怎么写,
我是在vbscript中写的