先执行where a=t1.a and b=t1.b在执行(Select max(c) from t1 接着where c in(Select max(c)最后
Select * from t1
Select * from t1
解决方案 »
- 一个关于50个不同方向的查询(上)
- 使用SQL语句查询结果值做字段进行新查询
- 各位大虾,我这里有关于存储过程的一个问题,谢谢指教
- 这可郁闷了,SQL 2005远程连接上去看是可以看到所有数据库
- 水平较低 能否帮助精简一下SQL语句。
- SQL字符串比较的疑难问题
- 昨天我不小心进行了误更新操作,把表中所有数据都变成重复的了,忘了备份,求高手帮忙!急!!!!!!
- 如何检测一个数据库的所有表中那些表有数据,有几行数据?
- 关于BCP 文本入库的问题!Error = [Microsoft][ODBC SQL Server Driver]字符串数据,右截位
- 在向一个表插入一条纪录的同时,向另一个表插入纪录,如何用触发器完成,再线等待,立即结账!thank you !!
- 行列转换问题
- 请教邹建:关联表问题,如何减少查询次数
估计要问微软开发sql的人了
首先,把 刚才的 语句 改成 这样 对吗?Select * from t1 t1 where c in(Select max(c) from t1 t2 where a=t1.a and b=t1.b)
要是 先执行where a=t1.a and b=t1.b的话a=t1.a and b=t1.b那么这个 t1 表的 别名 t1 是 怎么获得 的。
那么这个 t1 表的 别名 t1 是 怎么获得 的。其实这里的t1.a,t1.b并不是上一级的表,而是嵌套里的表,像
Select * from t1 t1 where c in(Select max(c) from t1 t2 where a=t1.a and b=t1.b)
如果在嵌套查询中真要 t1 t1,那应该是这样的
Select * from t1 t1 where c in(Select max(c) from t1 t1,t1 t2 where a=t1.a and b=t1.b)
其实下一级是不能用上一级的表的。
那么
a=t.a and b=t.b 用的 不就是 外面的 from tb t 吗?select t.* from tb t where c in(select max(c) from tb where a=t.a and b=t.b)select t.* from tb t where c in(select max(c) from tb where a=tb.a and b=tb.b)
b int null,
c int null,
)
在select t.* from tb t where c in(select max(c) from tb where a=t.a and b=t.b)中:
a=t.a and b=t.b 这一句中 a是tb中字段,t.a也是tb中字段 t是tb表的别名 就像人的姓名中有大号和小号一样,都是一个人.
'其实下一级是不能用上一级的表的' 这一句话应该不成立;
如果我这样的话:改成tb1一样可以通过
select t.* from tb1 t where c in(select max(c) from tb where a=t.a and b=t.b)再有就是你的第二条:
select t.* from tb t where c in(select max(c) from tb where a=tb.a and b=tb.b)中
select max(c) from tb where a=tb.a and b=tb.b 后面的条件有什么意义?
知道 关联子查询里 是怎么检索数据的
Select * from tb t1 where c in(Select max(c) from tb where a=t1.a and b=tb.b)
是这样吗
然后执行select * from t1 where c in tb;
如果这样呢?
Select * from t1 t1 where c in(Select max(c) from tb where a=t1.a and b=tb.b)
先执行
Select max(c) from tb where a=t1.a and b=tb.bt1.a 里的 t1 是从哪来的??