J
Jen
Hi,
I have a complex SQL Query that I am having some trouble with. I have
2 tables TestTable and Actual Table. I need to manipulate data from
each table for 2 different time periods. Using aliases for the tables,
I am able to get the correct values I need for the two time periods.
However, I don't want to show all the results. The average values are
typically between -50 and 50. I want only those whose absolute value
is greater than 5 to be displayed. Is there a way to hide the rest?
Also, is there a way to sort them by the absolute value?
SELECT Avg(T1.Param1-E1.Param1)-Avg(T2.Param1-E2.Param1) AS DiffP1,
Avg(T1.Param2-E1.Param2)-Avg(T2.Param2-E2.Param2) AS
DiffP2,
Avg(T1.Param3-E1.Param3)-Avg(T2.Param3-E2.Param3) AS
DiffP3
Avg(T1.Param4-E1.Param4)-Avg(T2.Param4-E2.Param4) AS
DiffP4
Avg(T1.Param5-E1.Param5)-Avg(T2.Param5-E2.Param5) AS
DiffP5
Avg(T1.Param6-E1.Param6)-Avg(T2.Param6-E2.Param6) AS
DiffP6
Avg(T1.Param7-E1.Param7)-Avg(T2.Param7-E2.Param7) AS
DiffP7
Avg(T1.Param8-E1.Param8)-Avg(T2.Param8-E2.Param8) AS
DiffP8
Avg(T1.Param9-E1.Param9)-Avg(T2.Param9-E2.Param9) AS
DiffP9
Avg(T1.Param10-E1.Param10)-Avg(T2.Param10-E2.Param10) AS
DiffP10
FROM TestTable AS T1 INNER JOIN ActualTable AS E1 ON
T1.DataTime=E1.DataTime, TestTable AS T2 INNER JOIN ActualTable AS E2
ON T2.DataTime=E2.DataTime
WHERE (((T1.DataTime) Between [Start Date] And [End Date]) AND
((T2.DataCaptureTime) Between [Start Date 2] And [End Date 2]));
Right now my results appear as:
DiffP1 DiffP2 DiffP3 DiffP4 DiffP5 DiffP6 DiffP7 DiffP8
DiffP9 DiffP10
-10 12 3 -6 -7 27 -14
-4 -8 9
I would like the following:
DiffP6 DiffP7 DiffP2 DiffP1 DiffP10 DiffP9
DiffP5 DiffP4
27 -14 12 -10 9 -8
-7 -6
And columns with DiffP3, DiffP8 are eliminated.
Any help would be greatly appreciated!!
Jen
I have a complex SQL Query that I am having some trouble with. I have
2 tables TestTable and Actual Table. I need to manipulate data from
each table for 2 different time periods. Using aliases for the tables,
I am able to get the correct values I need for the two time periods.
However, I don't want to show all the results. The average values are
typically between -50 and 50. I want only those whose absolute value
is greater than 5 to be displayed. Is there a way to hide the rest?
Also, is there a way to sort them by the absolute value?
SELECT Avg(T1.Param1-E1.Param1)-Avg(T2.Param1-E2.Param1) AS DiffP1,
Avg(T1.Param2-E1.Param2)-Avg(T2.Param2-E2.Param2) AS
DiffP2,
Avg(T1.Param3-E1.Param3)-Avg(T2.Param3-E2.Param3) AS
DiffP3
Avg(T1.Param4-E1.Param4)-Avg(T2.Param4-E2.Param4) AS
DiffP4
Avg(T1.Param5-E1.Param5)-Avg(T2.Param5-E2.Param5) AS
DiffP5
Avg(T1.Param6-E1.Param6)-Avg(T2.Param6-E2.Param6) AS
DiffP6
Avg(T1.Param7-E1.Param7)-Avg(T2.Param7-E2.Param7) AS
DiffP7
Avg(T1.Param8-E1.Param8)-Avg(T2.Param8-E2.Param8) AS
DiffP8
Avg(T1.Param9-E1.Param9)-Avg(T2.Param9-E2.Param9) AS
DiffP9
Avg(T1.Param10-E1.Param10)-Avg(T2.Param10-E2.Param10) AS
DiffP10
FROM TestTable AS T1 INNER JOIN ActualTable AS E1 ON
T1.DataTime=E1.DataTime, TestTable AS T2 INNER JOIN ActualTable AS E2
ON T2.DataTime=E2.DataTime
WHERE (((T1.DataTime) Between [Start Date] And [End Date]) AND
((T2.DataCaptureTime) Between [Start Date 2] And [End Date 2]));
Right now my results appear as:
DiffP1 DiffP2 DiffP3 DiffP4 DiffP5 DiffP6 DiffP7 DiffP8
DiffP9 DiffP10
-10 12 3 -6 -7 27 -14
-4 -8 9
I would like the following:
DiffP6 DiffP7 DiffP2 DiffP1 DiffP10 DiffP9
DiffP5 DiffP4
27 -14 12 -10 9 -8
-7 -6
And columns with DiffP3, DiffP8 are eliminated.
Any help would be greatly appreciated!!
Jen