If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Help with SQL statement in query
Others have contributed a SQL statement from another newsgroup (see below).
The only remaining issue is to add something to the expression so that it also displays the results of a sum of all [RESULT] values that have a "null" value in the [QUAL] field and not only compare them to those with "not null" values. Please see the ongoing thread here http://www.microsoft.com/communities...968&sloc=en-us SQL Statement: SELECT X1.LAB_ID, 'max_of' AS aggregate_type, MAX(IIF(X1.QUAL IS NULL, NULL, X1.[RESULT])) AS aggregate_value FROM Xylenes AS X1 WHERE NOT EXISTS ( SELECT * FROM Xylenes AS X2 WHERE X2.LAB_ID = X1.LAB_ID AND X2.QUAL IS NULL ) GROUP BY X1.LAB_ID UNION ALL SELECT X1.LAB_ID, 'sum_of', SUM(IIF(X1.QUAL IS NOT NULL, NOT NULL, X1.[RESULT])) FROM Xylenes AS X1 WHERE EXISTS ( SELECT * FROM Xylenes AS X2 WHERE X2.LAB_ID = X1.LAB_ID AND X2.QUAL IS NOT NULL ) GROUP BY X1.LAB_ID ORDER BY 1; -- Barry Guidry |
Thread Tools | |
Display Modes | |
|
|