SQL语句的简单问题

ba_saner 2003-12-23 10:31:57
有表

id scale
1 5
2 6
3 4
4
5 7
6 4
7
8 12
9 7

select top 4 * from table order by abs(scale-8)

执行后为什么是7,4,9,5行?如何才能不包括4,7行?
4,7行的scale是NULL
...全文
24 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenanigan 2003-12-23
  • 打赏
  • 举报
回复
select top 4 * from table where scale is not null order by abs(scale-8)
这句正确
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
刚才写错了是:
select top 4 * from table where scale is not null order by abs(scale-8)
DigJim 2003-12-23
  • 打赏
  • 举报
回复
或者

select top 4 * from table order by abs(scale-8) where ISNULL(scale ,'') <> ''
ba_saner 2003-12-23
  • 打赏
  • 举报
回复
select top 4 * from table order by abs(scale-8) where scale is not null

select top 4 * from table where scale is not null order by abs(scale-8)

以上两个句子那个正确?
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
sql中是用
where col1 is null
来判断

不能是
where col1=null
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
select top 4 * from table order by abs(scale-8) where scale is not null

34,593

社区成员

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

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