简体   繁体   English

使用另一个表中的列按组选择最大

[英]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.

相关问题 使用SUM和GROUP BY从一列中选择MAX,而不使用子查询 - SELECT MAX from one column with SUM and GROUP BY for another, without subqueries SQL在分组依据期间选择另一个具有最大值的列 - SQL select another column with max during group by MySQL:使用不同表中的值从组中选择最大值? - MySQL: Select max from group using the value from a different table? 从表中选择最大计数并更新另一列 - Select max of count from a table and update another column 如何在另一列上使用MAX从一行中选择字段? - How to select field from a row using MAX on another column? 通过另一列的MAX值进行分组 - Group By with MAX value from another column PostgreSQL GROUP BY:另一个WHERE上的SELECT列第三列= x - PostgreSQL GROUP BY: SELECT column on MAX of another WHERE a third column = x SQL选择一个表中的所有列和另一个表上另一列的最大值 - SQL Select all columns from one table and Max value of another column on another table 使用 DB2,如何为一列选择具有 MAX 的行,然后在结果子集上为同一表的另一列选择具有 MAX 的行? - Using DB2, how do you select rows with MAX for one column and then select rows with MAX on the resulting subset for another column on the same table? 找到一列的最大值,然后按同一表中的另一列分组 - Find the max value of a column, then group by another column in same table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM