你好我是这样的一个表:
ID | Name | Description | Location | Effec_Dte
----------------------------------------------
1 | Serv | OHCOD01 | NYNY | 2014-1-1
2 | Serv | OHCOD01 | CALA | 2014-1-1
3 | Serv | OHCOA11 | SCCO | 2014-5-1
4 | Serv | OHCOA11 | SCCO | 2014-5-1
...
在这个例子中有两个应用程序,一个在纽约和洛杉矶托管 另一个只在哥伦比亚举办。我想查找每个应用程序并检查第一行和第二行,以确定它们是在同一个城市还是在两个不同的城市中托管。
有办法做到这一点吗?
谢谢!
编辑:
SELECT NAME FROM TABLE
WHERE (//Logic to find all names that exist in two locations)
答案 0 :(得分:0)
属于两个或更多不同的城市
WITH CTE AS
(
SELECT *,
ROW_NUMBER() OVER(PARTITION BY Location ORDER BY ID ) AS Row
FROM Mytable
)
where CTE.Row>1
属于只有1个城市
WITH CTE AS
(
SELECT *,
ROW_NUMBER() OVER(PARTITION BY Location ORDER BY ID ) AS Row
FROM Mytable
)
where CTE.Row=1