Jon*_*ngu 0 sql oracle select count
我试图计算表格上出现的重复数量,例如:
First| Last | ADDR1 | City | ST | Zip -----+-------+-----------------+-----------+----+------ John | Smith | 1234 Fake St. | Hollywood | CA | 12345 John | Smith | 1234 Fake St. | Hollywood | CA | 12345 John | Smith | 1234 Fake St. | Hollywood | CA | 12345 John | Smith | 1234 Fake St. | Hollywood | CA | 12345 Jane | Smith | 1111 Junkertown | Phoenix | AR | 22222 Jane | Smith | 1111 Junkertown | Phoenix | AR | 22222 Jane | Smith | 1111 Junkertown | Phoenix | AR | 22222
这是我的select语句,但它不喜欢我的where语句.我只想返回计数> 1的行
select distinct t.first_name, t.last_name, t.addr_line_1, t.city,
t.state_cd, t.zip, count(*) as numberofdupes
from name_addr t
where numberofdupes > 1
group by t.first_name, t.last_name, t.addr_line_1, t.city, t.state_cd, t.zip
Run Code Online (Sandbox Code Playgroud)
如果有人能指出我正确的方向.谢谢,麻烦您了.
跳过该WHERE子句,HAVING用于聚合函数条件.
没必要SELECT DISTINCT,GROUP BY返回没有重复的行.
select t.first_name, t.last_name, t.addr_line_1, t.city,
t.state_cd, t.zip, count(*) as numberofdupes
from name_addr t
group by t.first_name, t.last_name, t.addr_line_1, t.city, t.state_cd, t.zip
having count(*) > 1
Run Code Online (Sandbox Code Playgroud)