如何使用完整的记录集获取ID

时间:2021-02-11 12:22:35

I have following table:

我有以下表格:

UserId      UserDb      Systolic    Diastolic   Weight      Height
----------- ----------- ----------- ----------- ----------- -----------
1000022     2           0           0           0           67
1000022     2           23          323         33          0
50508       30          3           3           33          39
51604       0           0           44          44          191
51318       0           0           0           0           0

How I can get UserId's with complete set of records? I mean that data can be scattered between records, like user with 1000022 id have height record in one row, and weight, systolic and diastolic in other rows.

如何通过完整的记录集获取UserId?我的意思是数据可以分散在记录之间,例如具有1000022 id的用户在一行中具有高度记录,并且在其他行中具有重量,收缩压和舒张压。

I have the solution with table variables but it isn't efficient and flexible. Is it possible to make such kind of query?

我有表变量的解决方案,但它没有效率和灵活性。是否可以进行此类查询?

I would like to get that ID's:

我想得到那个ID:

UserId
-----------
1000022
50508

1 个解决方案

#1


3  

SELECT  userID
FROM    TableName
GROUP   BY UserID
HAVING  MAX(UserDb) <> 0 AND
        MAX(Systolic) <> 0 AND
        MAX(Diastolic) <> 0 AND   
        MAX(Weight) <> 0 AND
        MAX(Height) <> 0

OUTPUT

╔═════════╗
║ USERID  ║
╠═════════╣
║   50508 ║
║ 1000022 ║
╚═════════╝

#1


3  

SELECT  userID
FROM    TableName
GROUP   BY UserID
HAVING  MAX(UserDb) <> 0 AND
        MAX(Systolic) <> 0 AND
        MAX(Diastolic) <> 0 AND   
        MAX(Weight) <> 0 AND
        MAX(Height) <> 0

OUTPUT

╔═════════╗
║ USERID  ║
╠═════════╣
║   50508 ║
║ 1000022 ║
╚═════════╝