我如何 [=10a 重复两个属性的行
how can I select a rows that repets two atributtes
我有一个 table 与 Destino 和 Tronco,Fecha,我需要将重复的 Destino 和 Tronco 分组
SELECT Destino
,Tronco
,Count(*) AS Countrows
FROM Hist_LDS
WHERE Fecha = '2020-10-28'
GROUP BY Destino
,Tronco
HAVING COUNT(*) > 1
enter image description here
结果为空
但是如果我 Select 没有计数,它就会消失
SELECT Destino
,Tronco
FROM Hist_LDS
WHERE Fecha = '2020-10-28'
enter image description here
你是说 Destino 还是 Tronco 重复?您目前正在做的是寻找它们两者组合的重复 - 这在您的示例数据列表中不存在。
如果是,请查看以下内容是否returns您所追求的。
如果没有,请提供样本数据,包括您认为应该出现在初始查询中的记录。
--Identify duplicated Tronco values
select Tronco, Count(*) As Countrows
INTO #TRONCO
From Hist_LDS
Where Fecha='2020-10-28'
GROUP BY Tronco
HAVING COUNT (*)>1
--Identify duplicated Destino values
select Destino, Count(*) As Countrows
INTO #DESTINO
From Hist_LDS
Where Fecha='2020-10-28'
GROUP BY DESTINO
HAVING COUNT (*)>1
--Identify records from initial table where Destino or Tronco were repeated
select Destino, Tronco, Count(*) As Countrows
From Hist_LDS
Where Fecha='2020-10-28'
AND (Destino in (SELECT destino from #DESTINO) OR Tronco in (SELECT tronco from #TRONCO))
我有一个 table 与 Destino 和 Tronco,Fecha,我需要将重复的 Destino 和 Tronco 分组
SELECT Destino
,Tronco
,Count(*) AS Countrows
FROM Hist_LDS
WHERE Fecha = '2020-10-28'
GROUP BY Destino
,Tronco
HAVING COUNT(*) > 1
enter image description here
结果为空 但是如果我 Select 没有计数,它就会消失
SELECT Destino
,Tronco
FROM Hist_LDS
WHERE Fecha = '2020-10-28'
enter image description here
你是说 Destino 还是 Tronco 重复?您目前正在做的是寻找它们两者组合的重复 - 这在您的示例数据列表中不存在。
如果是,请查看以下内容是否returns您所追求的。
如果没有,请提供样本数据,包括您认为应该出现在初始查询中的记录。
--Identify duplicated Tronco values
select Tronco, Count(*) As Countrows
INTO #TRONCO
From Hist_LDS
Where Fecha='2020-10-28'
GROUP BY Tronco
HAVING COUNT (*)>1
--Identify duplicated Destino values
select Destino, Count(*) As Countrows
INTO #DESTINO
From Hist_LDS
Where Fecha='2020-10-28'
GROUP BY DESTINO
HAVING COUNT (*)>1
--Identify records from initial table where Destino or Tronco were repeated
select Destino, Tronco, Count(*) As Countrows
From Hist_LDS
Where Fecha='2020-10-28'
AND (Destino in (SELECT destino from #DESTINO) OR Tronco in (SELECT tronco from #TRONCO))