sql server 有没有不等于号(!=)和减号的(minus),我这两道题这样做对不对?

昵称是可以中文吗 2011-11-08 07:41:32
奖状信息:作者编号, 获奖日期 作者信息:作者编号, 性别


A.
不获奖的作者信息:(sql server 有没有不等于号(!=)和减号的(minus))
1.select 作者信息.作者编号 from 作者信息 and 奖状信息 where 作者信息.作者编号!=奖状信息.作者编号
2.select 作者编号 from 作者信息 minus select 作者编号 from 奖状信息;
B.
查找10个最近获奖的奖状,并且按照顺序排列 select top 10 * from 奖状信息 order by 获奖日期 desc
...全文
523 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
mark一下select 1,又多学习了一个知识
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 pengxuan 的回复:]
SQL code

--A
select * from 作者信息 a where not exists(select 1 from 奖状信息 where 作者编号=a.作者编号)
--B
select top 10 * from 奖状信息 order by 获奖日期 desc
[/Quote]
select * from 作者信息 a where not exists(select 1 from 奖状信息 where 作者编号=a.作者编号)
这里的1可以换成*吧??
select * from 作者信息 a where not exists(select * from 奖状信息 where 作者编号=a.作者编号)
pengxuan 2011-11-08
  • 打赏
  • 举报
回复

--A
select * from 作者信息 a where not exists(select 1 from 奖状信息 where 作者编号=a.作者编号)
--B
select top 10 * from 奖状信息 order by 获奖日期 desc
黄_瓜 2011-11-08
  • 打赏
  • 举报
回复
except 
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 fredrickhu 的回复:]
SQL code
--2005+
select 作者编号 from 作者信息 except select 作者编号 from 奖状信息
[/Quote]
谢谢
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 p2227 的回复:]
引用 6 楼 scauscnu 的回复:

引用 4 楼 p2227 的回复:
引用 2 楼 scauscnu 的回复:

引用 1 楼 p2227 的回复:
sql是一种面向集合的语句。。。。你的思考方法就不对了

select 作者编号 from 作者信息 where 作者编号 not in ( select 作者编号 from 奖状信息)

第一个不能在where比较处,……
[/Quote]
没试过,之前学的是oracle,现在改学mssqlserver,就是好奇数据库有没有直接!=的说法,像下面的语句是不是成立的,在ms sqlserver环境下
select 作者信息.作者编号 from 作者信息 and 奖状信息 where 作者信息.作者编号!=奖状信息.作者编号
--小F-- 2011-11-08
  • 打赏
  • 举报
回复
--2005+
select 作者编号 from 作者信息 except select 作者编号 from 奖状信息
p2227 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 scauscnu 的回复:]

引用 4 楼 p2227 的回复:
引用 2 楼 scauscnu 的回复:

引用 1 楼 p2227 的回复:
sql是一种面向集合的语句。。。。你的思考方法就不对了

select 作者编号 from 作者信息 where 作者编号 not in ( select 作者编号 from 奖状信息)

第一个不能在where比较处,把比较条件定死吗?(where 作者信息.作者……
[/Quote]那你想象的语句放到 oracle里面能执行吗。因为现在需求不需要用那些语句,所以没用。
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 p2227 的回复:]
引用 2 楼 scauscnu 的回复:

引用 1 楼 p2227 的回复:
sql是一种面向集合的语句。。。。你的思考方法就不对了

select 作者编号 from 作者信息 where 作者编号 not in ( select 作者编号 from 奖状信息)

第一个不能在where比较处,把比较条件定死吗?(where 作者信息.作者编号!=奖状信息.作者编号
)
没看……
[/Quote]
我的疑问很简单,就是where后面的条件是作者表有,但是奖状里面没有的作者编号,直接用?(where 作者信息.作者编号!=奖状信息.作者编号
)
来表示罢了,貌似oracle里面有all,any some,like,between and,怎么都没看到你们用呢
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ssp2009 的回复:]
SQL code
select 作者信息.作者编号 from 作者信息 left join 奖状信息 on 作者信息.作者编号=奖状信息.作者
编号
where 作者信息.作者编号 is null
select 作者编号 from 作者信息 where 作者编号 not in (select 作者编号 from 奖状信息)


B正确
[/Quote]
select 作者信息.作者编号 from 作者信息 left join 奖状信息 on 作者信息.作者编号=奖状信息.作者
编号
where 作者信息.作者编号 is null

左连接,那么奖状表里的作者编号就固定死了,这个之前都没怎么用,还是要谢谢你啦
p2227 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 scauscnu 的回复:]

引用 1 楼 p2227 的回复:
sql是一种面向集合的语句。。。。你的思考方法就不对了

select 作者编号 from 作者信息 where 作者编号 not in ( select 作者编号 from 奖状信息)

第一个不能在where比较处,把比较条件定死吗?(where 作者信息.作者编号!=奖状信息.作者编号
)
[/Quote]没看懂你的意思
快溜 2011-11-08
  • 打赏
  • 举报
回复
select 作者信息.作者编号 from 作者信息 left join 奖状信息 on 作者信息.作者编号=奖状信息.作者
编号
where 作者信息.作者编号 is null
select 作者编号 from 作者信息 where 作者编号 not in (select 作者编号 from 奖状信息)

B正确
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 p2227 的回复:]
sql是一种面向集合的语句。。。。你的思考方法就不对了

select 作者编号 from 作者信息 where 作者编号 not in ( select 作者编号 from 奖状信息)
[/Quote]
第一个不能在where比较处,把比较条件定死吗?(where 作者信息.作者编号!=奖状信息.作者编号
)
p2227 2011-11-08
  • 打赏
  • 举报
回复
sql是一种面向集合的语句。。。。你的思考方法就不对了

select 作者编号 from 作者信息 where 作者编号 not in ( select 作者编号 from 奖状信息)

34,587

社区成员

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

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