SELECT DISTINCT多列以及其他列[重复]

时间:2022-01-29 04:28:25

This question already has an answer here:

这个问题在这里已有答案:

I want to run query like below

我想运行如下的查询

select distinct (columnA, columnB, columnC), columnD from MY_TABLE where columnA IS NOT NULL AND columnB IS NOT NULL AND columnC is NOT NULL;

I only want distinct of columnA, columnB and columnC and NOT ON columnD. But SQL developer is pointing an error right after columnA, How can I fix this?

我只想要不同的columnA,columnB和columnC以及NOT ON columnD。但是SQL开发人员在columnA之后指出了一个错误,我该如何解决这个问题呢?

I tried to fix my query using GROUP BY

我试图使用GROUP BY修复我的查询

select columnA, columnB, columnC, (select count(*) from TABLE2 WHERE table2columnA = myTable.columnA) from MY_TABLE myTable where columnA IS NOT NULL AND columnB IS NOT NULL AND columnC is NOT NULL GROUP BY columnA, columnB, columnC;

Notice that my columnD is actually another select statement? But this is giving me error

请注意我的columnD实际上是另一个select语句?但这给了我错误

ORA-00979: not a GROUP BY expression
00979. 00000 -  "not a GROUP BY expression"

This is not a duplicate of that another question

这不是另一个问题的重复

1 个解决方案

#1


SELECT DISTINCT a,b,c FROM t

is roughly equivalent to:

大致相当于:

SELECT a,b,c FROM t GROUP BY a,b,c,t

It's a good idea to get used to the GROUP BY syntax, as it's more powerful. It's a good idea to get used to the GROUP BY syntax, Please see this post:

习惯GROUP BY语法是个好主意,因为它更强大。习惯GROUP BY语法是个好主意,请看这篇文章:

Possible duplicate ?

可能重复?

#1


SELECT DISTINCT a,b,c FROM t

is roughly equivalent to:

大致相当于:

SELECT a,b,c FROM t GROUP BY a,b,c,t

It's a good idea to get used to the GROUP BY syntax, as it's more powerful. It's a good idea to get used to the GROUP BY syntax, Please see this post:

习惯GROUP BY语法是个好主意,因为它更强大。习惯GROUP BY语法是个好主意,请看这篇文章:

Possible duplicate ?

可能重复?