具体要查哪个字段,你自己修改吧,我帮你把表之间的链接条件写出来。
成都创新互联公司服务项目包括青田网站建设、青田网站制作、青田网页制作以及青田网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,青田网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到青田省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
select a.*, b.*, c.* from a, b, c where a.a1 = b.b1 and a.a2 = c.c2 and a2 = an
解决方案
既然知道了问题所在,那么久好解决了。找到SQL SERVER安装路径,Binn目录下,找到这个文件:
右键用超级管理员账户运行,就可以发现Sql server提供服务了!
sqlserverstart
虽然运行成功了,但是总不能每次去运行吧。所以我再写一段批处理,保存为bat文件运行即可。批处理内容:
@echo off
SC CREATE mssqlserver binPath= "D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn\sqlservr.exe" DisplayName= "SQL Server" start= auto
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mssqlserver /v Description /t REG_SZ /d "用于提供SQL SERVER服务的服务,如果停止,则无法提供SQL SERVER服务。"
NET START mssqlserver
注意:以上代码中路径部分,请修改为本机Sqlserver安装路径。
假设学生表叫student,课程表叫class,选课表叫choose
1.三层嵌套的问题
select student.name from student where student.id IN
(select choose.sid from choose where choose.cid NOT IN
(select class.id from class where class.teacher='李明'))
2.一个内连接,一个嵌套
select student.name,avg(choose.score) from
student inner join choose on student.id=choose.sid
where student.id IN
(select choose.sid from choose
where choose.score'60'
group by choose.sid
having count(choose.sid)=2)
gruop by student.id
3.一个联合查询,一个嵌套查询
select student.name from student
where student.id IN
(select c1.sid from choose c1 where choose.cid='1'
union
select c2.sid from choose c2 where choose.cid='2'
on c1.sid=c2.sid
)
4.其实就是自连接查询和行列交换的问题:
select student.id,
(case choose.id when '1' then choose.score end) as 1号课成绩,
(case choose.id when '2' then choose.score end) as 2号课成绩,
from student inner join choose on student.id=choose.sid sc1,
student inner join choose on student.id=choose.sid sc2
where sc1.id='1'
and sc2.id='2'
and sc1.scoresc2.score