本文介绍了SQL Server中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用三个表,例如..学位,系和学生.

学位(DID,DegreeName)
部门(DepID,DID,部门名称)
学生(RegNo,姓名,DID,DepID)



我想显示此格式..


学位系学生

a 10 21

b 5 17

c 0 0

d 1 0

e 0 0


请帮帮我...................
感谢和问候
Sravan ..

Hi,

i am using three tables like.. Degree,Department,and Students.

Degree(DID,DegreeName)
Department(DepID,DID,DepartmentName)
Student(RegNo,Name,DID,DepID)



I want to display this Format..


Degree Department Students

a 10 21

b 5 17

c 0 0

d 1 0

e 0 0


Pls Help me...................
Thanks And Regards
Sravan..

推荐答案


select DegName,
(Select COUNT(1) from Department where DegreeId=a.DegID) as Departmentcount,
(Select COUNT(1) from students where deptId in (Select deptId from Department where DegreeId=a.DegID)) as Studentscount
from degree a


这篇关于SQL Server中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:47