我要排除计数以删除以下查询中的重复内容
SELECT *, count(1) as count except (count)
FROM PRD.sites
group by site,id ,site_desc,timestamp
having count(1) < 2
,但在[1:29]出现了意外的关键字EXCEPT错误。 我正在使用standardSQL
答案 0 :(得分:2)
您可以在下面尝试
select * except(count)
from
(
SELECT *, count(1) as count
FROM PRD.sites
group by site,id ,site_desc,timestamp
having count(1) < 2
)X
或者您可以使用row_number()查找重复项
SELECT * except(rn)
FROM (
SELECT
*,
ROW_NUMBER()
OVER (PARTITION BY site,id ,site_desc,timestamp) as rn
FROM FROM PRD.sites
)
WHERE rn= 1
答案 1 :(得分:1)
您甚至不需要将COUNT()包含在SELECT列表中-下面将非常有用,并且将根据列出的字段删除重复的行
#standardSQL
SELECT AS VALUE ANY_VALUE(t)
FROM PRD.sites t
group by site,id ,site_desc,timestamp
having count(1) < 2
上方将仅显示没有重复的行(基于分组依据中的字段)
如果您需要根据字段删除重复项,请在下面使用
#standardSQL
SELECT AS VALUE ANY_VALUE(t)
FROM PRD.sites t
group by site,id ,site_desc,timestamp
如果您需要基于整个行进行重复数据删除-您可以在下面使用
SELECT DISTINCT *
FROM PRD.sites
答案 2 :(得分:0)
您可以尝试使用临时表
/* Get the data into a temp table */
SELECT * INTO #TempTable
FROM YourTable
/* Drop the columns that are not needed */
ALTER TABLE #TempTable
DROP COLUMN ColumnToDrop
/* Get results and drop temp table */
SELECT * FROM #TempTable
DROP TABLE #TempTable