1

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.

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:

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

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 ║
╚═════════╝
于 2013-03-25T12:27:12.610 に答える