选择1列SQL Server上具有重复值的行

时间:2019-01-11 07:25:42

标签: sql sql-server

使用SQL Server,我有:

     DATE                Cookie
===============================
1   10/04/2018 11:00:00   123
2   10/04/2018 12:00:00   123
3   10/04/2018 13:00:00   321
4   10/04/2018 14:00:00   123

我想要什么:

    DATE                Cookie
================================
3   10/04/2018 13:00:00  321

我真的需要一些帮助,谢谢大家。

5 个答案:

答案 0 :(得分:0)

您可以在下面尝试-

select * from tablename a
  where exists (select 1 from tablename b where a.Cookie=b.Cookie having count(b.Cookie)=1)

答案 1 :(得分:0)

因此,您只需要Cookie包含一个条目的行。可以这样做:

SELECT * 
FROM TableA AS A
WHERE Cookie IN ( SELECT Cookie, COUNT(*) 
                  FROM TableB AS B
                  GROUP BY Cookie
                  HAVING COUNT(*) = 1 )

答案 2 :(得分:0)

您可以通过以下方式使用input_layer = Input(shape=(size, size, chs)) norm = Lambda(pre_process, output_shape=(size, size, chs))(input_layer) conv_1 = Conv2D(16, kernel_size=(1, 1), strides=(1, 1), padding='valid', activation='relu')(norm) ,但可以在{fa06的解决方案中使用in

exists

答案 3 :(得分:0)

您可以使用此:

SELECT Cookie,
    MAX[DATE]
FROM table_name
GROUP BY Cookie
HAVING COUNT(*) = 1;

答案 4 :(得分:0)

您可以使用NOT EXISTS

SELECT t.*
FROM table t
WHERE NOT EXISTS (SELECT 1 FROM table t1 WHERE t1.Cookie = t.Cookie AND t1.DATE <> t.DATE);

如果(CookieDATE)上有合适的索引,这样做会更好。