SQL Server中的表 [英] tables in sql server

查看:75
本文介绍了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..

推荐答案

使用分组依据获取学生人数,然后按学位和学科分组结果.




从...中选择人数(学生),系,学位.
按部门,程度分组
Use group by to get the number of students and then group your result by degree and department.


Something like

select count(students), department, degree from ....
group by department, degree


尝试一些像这样的瘦身.

Try some thin like this.

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中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆