求查询语句!在线等待!高分相送 or others

渔夫 2003-10-10 10:56:32
遇到一个这样的问题:
表一(students)ID,name,sex,birth
表二(teachers)学生选课表 : ID,stuId,subject,score

1、查找学生的所有信息,和部分课程信息,
2、学生信息一个不少,一个也不能多。
3、课程任选一个(无所谓)也就是说设掉一部分数据,保留学生的全部信息。
请各位高手赐教。
mail:yxz@citsguilin.net
...全文
47 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
渔夫 2003-10-15
  • 打赏
  • 举报
回复
微软公司的bug.
渔夫 2003-10-15
  • 打赏
  • 举报
回复
为什么这个问题这么难
渔夫 2003-10-14
  • 打赏
  • 举报
回复
还不行
gmlxf 2003-10-13
  • 打赏
  • 举报
回复
select * from students a,teachers b where
a.id=b.id


select * from students a left join (
select * from teachers tem where ID=(select max(ID) from teachers where stuId=tem.stuId)
) b on a.id=b.stuId

查出来好象一样
gmlxf 2003-10-13
  • 打赏
  • 举报
回复
我想这个苯方法应该可以吧:
select
(select ID from students where ID=a.ID) as ID,
(select name from students where ID=a.ID) as name,
(select sex from students where ID=a.ID) as sex,
(select birth from students where ID)=a.ID as birth,
a.subject,a.score from teachers a
orcale 2003-10-13
  • 打赏
  • 举报
回复

select * from students a,teachers b where
a.id=b.id
maoyesky 2003-10-13
  • 打赏
  • 举报
回复
上面寫錯了
select identity(int,1,1) as nowid,* into #temp from teachers

select a.ID,a.name, a.sex,a.birth,b.ID,b.subject,b.score from students a left join (select ID,stuId,subject,score from teachers where nowid in (select
min(nowid) from #temp group by stuId)) b on a.ID=b.stuID
maoyesky 2003-10-13
  • 打赏
  • 举报
回复
select identity(int,1,1) as nowid,* into #temp from teachers

select a.ID,a.name, a.sex,a.birth,b.ID,b.subject,b.score from students a left join (select ID,stuId,subject,score from teachers where nowid in (select
min(nowid) from teachers group by stuId)) b on a.ID=b.stuID

pengdali 2003-10-13
  • 打赏
  • 举报
回复
select * from students a left join (
select * from teachers tem where ID=(select max(ID) from teachers where stuId=tem.stuId)
) b on a.id=b.stuId
渔夫 2003-10-13
  • 打赏
  • 举报
回复
各位,这里面所有的都不能达到要求,microsoft mssql 根本就不让舍掉数据库记录。所以用作联接,都不能实现。
但是如果在里面采用max 函数会导致select * 不能用。请问有没有不用存储过程的别的办法
pengdali 2003-10-10
  • 打赏
  • 举报
回复
select a.*,b.subject,b.score
from students a left join teachers b on a.id=b.stuid

或:

select a.*,b.subject,b.score
from teachers b right join students a on a.id=b.stuid
zjcxc 元老 2003-10-10
  • 打赏
  • 举报
回复
左连接:

select a.*,b.subject,b.score
from students a left join teachers b on a.id=b.stuid
aierong 2003-10-10
  • 打赏
  • 举报
回复
left join
txlicenhe 2003-10-10
  • 打赏
  • 举报
回复
Select a.*,b.subject,c.score from students a
Left Join
(Select stuID,min(id) as id from teachers group by stuID) b on a.id = b.stuID
left join teachers c on b.id = c.id

伍子V5 2003-10-10
  • 打赏
  • 举报
回复
1\select a.name,a.sex,a.birth,isnull(b.subject,''),isnull(b.score,0) from students a
left join teachers b on a.ID=b.ID
welyngj 2003-10-10
  • 打赏
  • 举报
回复
1.select s.*,stuid,subject ,score from students s left join teachers t on s.[id]=t.[id]
2,select t.stuid, name,sex,birth from students s left join on teachers t on s.id=t.id

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧