数据库子查询 问题

[复制链接]
查看11 | 回复2 | 2012-2-22 16:46:47 | 显示全部楼层 |阅读模式
这个比较方法好怪异,不过确实能得出结果Select *
from saless where 3 >(select count(*)from sales where s.salesamt >salesamt)这个是找出3个最小的select count(*)from sales where s.salesamt >salesamt这个实际上是求对于s表的某一行来说,到底有多少行比s.salesamt要小。比如有0行,那么s.salesamt肯定是最小的,而 3 > 0 成立,所以该行会被求出如果有10行比s.salesamt小,说明它肯定不是最小的那几个, 3 > 10 也不成立,所以不会求出...
回复

使用道具 举报

千问 | 2012-2-22 16:46:47 | 显示全部楼层
为什么这么写?最小的:selecttop 3 * from sales order by salesamt 最大的select top 3 * from sales order by salesamt desc 如果要显示在一个结果表里,加union就可以.有排序的方法为嘛还要一个一个比较?...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行