Make sure each entry has the same value for each input.

ID  |             LastAccessed         |   loginID   |
======================================================
1   |      02-15-2018 16:00:45:300     |    admin    |
2   |      02-15-2018 16:00:45:300     |    admin    |
3   |      02-15-2018 18:44:55:108     |    johny    |
4   |      02-15-2018 11:52:34:206     |    sarah    |
5   |      02-15-2018 11:52:34:206     |    sarah    |
6   |      02-15-2018 11:52:34:206     |    sarah    |
7   |      02-15-2018 11:52:34:206     |    sarah    |

In this table, I want to verify that everyone loginIDhas the same value for all of their respective values LastAccessed.

For example, we see that adminthey sarahhave the same meaning LastAccessed. I guess we can get two bills and make sure they are the same?

I need to check this for a set of about 8000 records.

+4
source share
3 answers

Or you can try a separate group by combination, for example below

select loginId 
from table
group by loginId
having count(distinct LastAccessed) >1;
+3
source

You can get loginIdthat have different meanings using:

select loginId
from t
group by loginId
having min(LastAccessed) <> max(LastAccessed);
+1
source

, :

SELECT Count(*) DistCount ,LoginId,LastAccessed         
FROM [LOGIN]
GROUP BY LastAccessed ,LoginId
HAVING COUNT(*) > 1        

, LoginId,LastAccessed.

If you need only Login. You can change the query as follows.

SELECT DISTINCT LoginId
FROM 
(
    SELECT Count(*) DistCount ,LoginId,LastAccessed         
    FROM [LOGIN]
    GROUP BY LastAccessed ,LoginId
    HAVING COUNT(*) > 1       
) T
+1
source

Source: https://habr.com/ru/post/1693666/


All Articles