Only getting 1 row of data while using SELECT Subqueries
550225Dec 6 2006 — edited Dec 6 2006Hi !
I am trying to find data from a database. I want to make an automatic Operability calculation script. I can easily find the instances when data signals have gone bad by using the following statement :
SELECT Name, OCCNUM, IP_Trend_Time, IP_Trend_Qstatus, IP_Trend_Qlevel FROM "FT-20223".1
WHERE IP_Trend_Time BETWEEN '01-oct-06 00:00:00'
AND '31-oct-06 24:00:00'
AND IP_Trend_Qstatus <> 'Good';
This gives me the following output :
Name OCCNUM IP_Trend_Time IP_Trend_Qstatus IP_Trend
------------------------ ---------- -------------------- ---------------- ---------------
FT-20223 56674 31-OCT-06 11:12:17.7 Bad Bad
FT-20223 56675 31-OCT-06 11:02:18.4 Bad Bad
FT-20223 56676 31-OCT-06 11:01:39.1 Scan Off Bad
FT-20223 56677 31-OCT-06 11:01:39.0 Bad Bad
FT-20223 56678 31-OCT-06 10:34:10.3 Bad Bad
FT-20223 68357 25-OCT-06 08:33:35.2 Bad Bad
FT-20223 76043 20-OCT-06 14:39:14.2 Bad Bad
FT-20223 98696 05-OCT-06 12:24:40.0 Bad Bad
FT-20223 98697 05-OCT-06 12:24:05.1 Bad Bad
FT-20223 102558 03-OCT-06 03:21:14.2 Bad Bad
FT-20223 105299 01-OCT-06 09:22:47.3 Bad Bad
FT-20223 105300 01-OCT-06 09:22:22.3 Bad Bad
FT-20223 105301 01-OCT-06 09:11:24.1 Unavailabl Bad
Which are all the instances that the system has had bad inputs. The problem is that i want to fint the time that the signal has been bad, which means that i need to find out where the signal has been good. I need to find out when the signal turned bad and when the signal went from bad to good again.
I tried using ;
SELECT Name, OCCNUM, IP_Trend_Time, IP_Trend_QStatus, IP_Trend_QLevel FROM "FT-20223"
WHERE OCCNUM = (SELECT (OCCNUM -1) FROM "FT-20223"
WHERE IP_Trend_Time BETWEEN '01-oct-06 00:00:00'
AND '31-oct-06 24:00:00'
AND IP_Trend_QStatus NOT LIKE 'Good')
And I Tried using;
INSERT INTO MODULE.TimeMinus(TimeMinus)
SELECT IP_Trend_Time FROM "FT-20223".1
WHERE IP_Trend_Time BETWEEN '01-oct-06 00:00:00'
AND '31-oct-06 24:00:00'
AND OCCNUM = (SELECT (OCCNUM -1) FROM "FT-20223"
WHERE IP_Trend_Time BETWEEN '01-oct-06 00:00:00'
AND '31-oct-06 24:00:00'
AND IP_Trend_QStatus NOT LIKE 'Good');
And both of these methods only give me the first result ;
31-OCT-06 11:12:52.0
Anyone have a clue as to how i can get results for all my 13 bad results ?