[英]select max using group by column from another table
Given the following tables: 给出下表:
tableA(v1,v2)
tableB(v3,v4)
tableC(v5,v6)
I want to write a query like the following one: 我想编写一个查询,如下所示:
SELECT MAX(v1)
FROM tableA
WHERE v2 IN (SELECT v3
FROM tableB
WHERE v4 IN (SELECT v5
FROM tableC
)
)
GROUP BY v6
Is something like this possible only by using IN?? 只有通过使用IN才有可能发生这种情况? I know how to write it by using JOINs between my three tables but I don't want to use JOINs. 我知道如何通过在三个表之间使用JOIN来编写它,但是我不想使用JOIN。
No, it's not possible to do this without using JOIN
(at least in MS-SQL). 不,如果不使用JOIN
(至少在MS-SQL中)是不可能做到这一点的。
Expressions in the GROUP BY clause can contain columns of the tables, derived tables or views in the FROM clause. GROUP BY子句中的表达式可以包含表的列,FROM子句中的派生表或视图。 The columns are not required to appear in the SELECT clause list. 这些列不需要出现在SELECT子句列表中。
http://msdn.microsoft.com/en-us/library/ms177673.aspx http://msdn.microsoft.com/en-us/library/ms177673.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.