SQL query computation help
Hi,
I have a query which computes values and assigns alias names to it. If I want to do more computations in the same query using already computed values, how can I achieve it?
For example,
If I have a table with columns A, B ,C,D and it has one row 1,2,3,4
TABLE
A B C D
1 2 3 4
The query looks like this
Select A, (A+B+C+D) Sum_all, (A+B) Sum_three from table;
Now in my select statement If I need one more value say (C+D), How can I accomplish this with already computed values (Sum_all and Sum_three) ?
Thanks in advance.
Hi,
So you want to say
sum_all - sum_threerather than
c + d? Personally, I find the second way easier and clearer, and they aren't necessarily the same if the columns can be NULL, but I think I understand your question.
Aliases assigned in the SELECT clause can't be referenced in the same SELECT clause.
You can get around that by assigning aliases in a sub-query, then referencing them in a super-query, like this:
WITH sub_q AS
Select A, (A+B+C+D) Sum_all, (A+B) Sum_three from table_x
SELECT sub_q.*
, sum_all - sum_three AS sum_cd
FROM sub_q;
Similar Messages
-
Cluster bar chart- sql query please help-
Hi,
I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
Here is my table
city region issue value
c1 north i1 y
c1 north i2 y
c2 north i1 n
c2 north i2 y
c3 south i1 y
c3 south i2 n
c4 east i1 n
c4 east i2 n
The bar chart will have 3 series, north south and east.
And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
How can I get something like this from the above table-
region issue count(yes)
north i1 1
north i2 2
south i1 1
south i2 0
east i1 0
east i2 0
thanksWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
Hi All,
Could you please help me out the below SQL query tuning .
Temp table is having 1 Million records
Master table is having 60 Million records
Query :
SELECT B.*,U.ID, SD, LE, LAE
FROM client.Temp B, client.Master
U WHERE U.policyno = B.policyno
AND B.UPFLAG = 0
1. Indexes are created on both email columns and Upflag for both tables.
2. Gathered DBMS Stats for MASTER Table
Data is loading 100k/hour on production .When your query takes too long ...
When your query takes too long ...
HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting -
Passing parameter to a SQL query - Please help
Hi All,
I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
The query is
String username1="le";
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
pstmt.setString(1, username1);
pstmt.executeQuery();
ResultSet rs = pstmt.getResultSet();
I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
I am getting the error:
SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
I changed the query to
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
//pstmt.setString(1, username1);
pstmt.executeQuery();
This time , it is not giving the error and retrieving properly.
But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
Please help.
Cheers,
charles_amhi,
try this...
String username1="%le%";
pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
pstmt.setString(1,username1);
cheers,
rpk -
Hi All,
We have a native SQL query accessing Oracle database(given below).
Can anyone please let me know what this query is about and how can we fine tune the query?
SELECT O.OBJECT_NAME ,
H.SID,
HS.MACHINE,
HS.PROCESS,
W.SID,
WS.MACHINE,
WS.PROCESS,
H.CTIME,
W.CTIME,
WS.ROW_WAIT_OBJ#,
WS.ROW_WAIT_FILE#,
WS.ROW_WAIT_BLOCK#,
WS.ROW_WAIT_ROW#,
HP.SPID,
WP.SPID
FROM V$LOCK H, V$LOCK W, V$LOCK I, V$LOCK I2, ALL_OBJECTS O,
V$SESSION HS, V$SESSION WS, V$PROCESS HP, V$PROCESS WP
WHERE H.ID1 = W.ID1
AND H.SID <> W.SID
AND H.TYPE IN ('TX','DL')
AND H.REQUEST = 0
AND H.SID = I.SID
AND I.TYPE = 'TM'
AND I.ID1 = O.OBJECT_ID
AND I.ID1 = I2.ID1
AND W.SID = I2.SID
AND I2.TYPE = 'TM'
AND H.SID = HS.SID
AND W.SID = WS.SID
AND HS.PADDR = HP.ADDR
AND WS.PADDR = WP.ADDR
INTO :EXCL_LOCK_WAITERS-OBJ_NAME ,
:EXCL_LOCK_WAITERS-HOLDER_SID ,
:EXCL_LOCK_WAITERS-H_HOSTNAME ,
:EXCL_LOCK_WAITERS-HOLDER_PID ,
:HOLDER_PID ,
:EXCL_LOCK_WAITERS-WAITER_SID ,
:EXCL_LOCK_WAITERS-W_HOSTNAME ,
:EXCL_LOCK_WAITERS-WAITER_PID ,
:WAITER_PID ,
:EXCL_LOCK_WAITERS-HELD_SINCE ,
:EXCL_LOCK_WAITERS-WAITSSINCE,
:ROW_WAIT_OBJ,
:ROW_WAIT_FILE,
:ROW_WAIT_BLOCK,
:ROW_WAIT_ROW,
:H_PROCESS,
:W_PROCESS
ENDEXEC
Thanks in advance.
Neethu MohanHi Neethu,
It gives you an overwiew of blocking Oracle sessions.
1. In general, the SQL checks Oracle sessions (SID's) that were requirering a DML lock ('TM') and now holding row locks (TX) to prevent destructive interference of simultaneous conflicting DML or DDL operations. DML statements automatically acquire both table-level locks and row-level locks ('TX') => holders
It joins these with the sessions that are waiting of releasing the lock by the holders => waiters.
2. it retrieves the detail information wich Oracle process , the object (table) , it's row , block and file
are affected by the locks.
3. Normally, the locks are only hold for a short period of time. If you have blocking sessions it may be of a log running task (i.e. mass data update of a table) ; but it could also be a application bug due to improper handling of concurrent updates of the same object.
4. Tuning
V$tables are expensive to query: Why?
v$ tables are generally Oracle memory structures.
v$ tables are not read consistent.
v$ tables require latches to access -- cannot modify and read memory at the same
time.
heavy access to v$ tables like this may cause some serious heavy duty contention.
Especially if you self join V$lock several times.
So the best would be to save the contents of V$LOCK in some table:
Create table mylocks as select * from v$lock;
Use that table for self-joining and joins to the other tables.
You can also CTAS the other v$ tables to bypass the performance bottleneck while retrieving
v$ directly.
You can empty or drop the created tables any time for new data.
Because you want to investigate only lock hold for a longert time to copy the v$ memory structures into
physical tables is not a disadvantage. You certainly will wait longer on finishing your query
instead of copy them into the tables.
Hope this helped
yk -
Hi,
I have a question about the performace of this SQL query. I have to display only 8 rows from this query. How is this query will be executed? What happens if the inside query returns more than 500 rows? Will it slow down?
SELECT * FROM (SELECT prod_date, create_date, prod_name, priority, status FROM CUST_PROD
WHERE cust_id = 100 and Status in(1, 5) order by priority, prod_name ) WHERE ROWNUM < = 8
Thank you..Its hard to tell what effect more data will have on a query until it happens. As BluShadow pointed out you're not talking about huge amounts of data; with luck the numbers you mentioned will not make any difference.
It looks like you're using the inline view to a top N query. You could look into using the RANK() function to do something similar. -
I need to denormalize data in sql query, please help!
With the query
select ref, start_time, end_time, person
from appointments
I get, eg:
REF START_TIME END_TIME PERSON
1234 10:00 11:00 USER1
1234 10:00 11:00 USER2
The users want to see it like this:
REF START_TIME END_TIME PERSON
1234 10:00 11:00 USER1, USER2
How do I do this just in sql?
cheers
Tracey.Apologies, my mistake, I forgot to connect by the ref as well...
(Note: you can ignore the CAST to VARCHAR2(40) as that just helped me get the formatted output.)
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1234 as ref, '10:00' as start_time, '11:00' as end_time, 'USER1' as person from dual union all
2 select 1234, '10:00', '11:00', 'USER2' from dual union all
3 select 345, '11:00', '12:00', 'USER3' from dual)
4 -- END OF TEST DATA
5 select ref, start_time, end_time, CAST(MAX(LTRIM(SYS_CONNECT_BY_PATH(person,', '),', ')) AS VARCHAR2(40)) as users
6 from (select ref, start_time, end_time, person
7 ,row_number() over (partition by ref, start_time, end_time order by person) rn
8 from t) t
9 CONNECT BY rn = PRIOR rn+1 AND ref = PRIOR ref
10 START WITH rn = 1
11* GROUP BY ref, start_time, end_time
SQL> /
REF START END_T USERS
1234 10:00 11:00 USER1, USER2
345 11:00 12:00 USER3
SQL> -
Hi experts,
what i want to do is write a single query which will show whether a employee
exits in the company or not.I have two tables emp and dept.There are as follows.
SQL> select * from emp;
NAME DEPTNO EMPNO
xxx 10 33036
YYY 12 2345
ZZZ 13 678
KKK 14 5678
RRR 15 7865
SQL> select * from dept;
DEPTNO LOCATION
10 AAA
11 BBB
12 CCC
13 DDD
what i want is it will select records from the emp table and find whether corrosponding
deptno really exists in the dept table.If the value is found in deptno column the dept table then it will set the value
Y other wise it will be N and all i have to do with the help of a single query.
expected result
name empno exists
xxx 33036 Y
YYY 2345 Y
ZZZ 678 Y
KKK 5678 N
RRR 7865 N
Please help.
Regards
RajatSELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST
FROM EMP
ORDER BY 1
Demo
SQL> WITH EMP AS(
2 SELECT 'XXX' NAME , 10 DEPTNO ,33036 EMPNO FROM DUAL UNION
3 SELECT 'YYY', 12, 2345 FROM DUAL UNION
4 SELECT 'ZZZ', 13 ,678 FROM DUAL UNION
5 SELECT 'KKK', 14 ,5678 FROM DUAL UNION
6 SELECT 'RRR', 15 ,7865 FROM DUAL ),
7 DEPT AS(
8 SELECT 10 DEPTNO,'AAA' DNAME FROM DUAL UNION
9 SELECT 11 ,'BBB' FROM DUAL UNION
10 SELECT 12 ,'CCC' FROM DUAL UNION
11 SELECT 13 ,'DDD'FROM DUAL )
12 SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N')
EXIST
13 FROM EMP
14 ORDER BY 1
15 /
EMPNO NAM EMPNO E
678 ZZZ 678 Y
2345 YYY 2345 Y
5678 KKK 5678 N
7865 RRR 7865 N
33036 XXX 33036 Y
SQL> Edited by: Salim Chelabi on Dec 7, 2008 4:15 AM -
Hi All,
I have a table that has 2 columns X, and Y.
create table temp(
x number(5);
y number (5);
);I am trying to write a query to check both columns, here is what I mean.
SELECT CASE
IF X = 1 AND Y = 0 THEN 3
IF X = 2 AND Y = 1 THEN 4
IF X = 4 AND Y IS NULL THEN 5
END AS STATUS
FROM .....temp ...etc.I know what I want but having problems with the syntax.
Thanks in Advance for your help.
I'm using Oracle 11g, SQL Dev 3.0select case when x = 1 and y = 0 then 3
when x = 2 and y = 1 then 4
when x = 4 and y is null then 5
else null
end ans
from ...for more on the case syntax see either one of these links.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/case_statement.htm
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions004.htm -
How to add pl sql query into help text of an item.
Hi
In my database i have added comments to the colums. I would like to use this comments in the help text of the items of my application. I have the query but when I use it in the help text attribute it does not execute the query, it presents the query.
Any ideas?It is probably too late now, but note that if you create your application using the Create Application Wizard and Application Models, based on User Interface Defaults created in the SQL Workshop, any column comments will automatically become application help text.
-
Table1
QTE_ID SEQ_NO
1435177 2
1435177 5
1435177 7
1435177 8
1435177 12
1435177 14
Table2
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 1 98500
1435177 2 98500
1435177 3 0
1435177 4 98500
1435177 5 98500
1435177 7 98500
1435177 8 98500
1435177 11 59300
1435177 12 59300
1435177 14 59300
The result should be
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 2 0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
1435177 5 0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
1435177 7 0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
1435177 8 0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
1435177 12 0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
1435177 14 0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
Please help me in writing the query.
Thanks in advance.
SrinivasWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
What's wrong with this sql query? Help
hi
i am having difficulty executing this query
ResultSet s=st.executeQuery("select * from employee where iden = ?"+id);
here in my program st is statement obg
iden is attribute name in table
id i am getting at run time from user
please help...it says wrong number of parameters
thank youThat's correct, get rid of the Question mark. Questions marks are used in PreparedStatements, but they are also used in pattern matching. I am assuming the iden is the table identity. Therefore, I am assuming it is numeric. If so, you can't use the question mark because pattern matching is only done with strings. If you are treating your statement as a PreparedStatement, then you have done it wrong. (See the API) Here is a code snippet from the API:PreparedStatement pstmt =
con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)It seems you are using a Statement object, so, you need to get rid of that question mark.
tajenkins -
SQL Query, please help very urgent
I am a newbie is sql.
I have two tables called test_master and test_detail.
Both tables contains pos_id as common field.
In test_detail got sub_id and to get the people under a given pos_id, I join with pos_id of test_master.
In the where condition, when I give the pos_id, it's returning only
the first level. How can I get the second level and get all the levels?
Any help is highly appreciable.It's very urgent.
Looking forward to hear from you.
Thanks
NewbieOk, I am pasting the description of the master and detail in the order.
Master
EMPLOYEE_NO VARCHAR2(30)
ORGANIZATION_ID NUMBER(15)
ORGANIZATION_NAME VARCHAR2(240)
POSITION_ID NUMBER(15)
POSITION_NAME VARCHAR2(240)
Detail
POSITION_ID NUMBER(15)
SUBORDINATE_ID NUMBER(15)
ORGANIZATION_ID NUMBER(15)
POSITION_NAME VARCHAR2(50)
Here is the sql, I want to get all the subordinates under a given position_id of the master.
Looking forward to hear from you.
select a.employee_no,a.POSITION_ID,a.POSITION_NAME,a.EMPLOYEE_NAME,
b.position_id,b.subordinate_id from portal_employee_master_test a,
portal_structure_test b
where a.POSITION_ID = b.POSITION_ID and a.POSITION_ID='xyz'
and b.position_ID=a.POSITION_ID -
SQL query urgent helps needed!!!
Hi all,
I got the following query :-
SELECT RH.REQUEST_NUMBER,
MSIK.CONCATENATED_SEGMENTS,
MSIK.DESCRIPTION,
RL.FROM_SUBINVENTORY_CODE,
RL.UOM_CODE,
RL.QUANTITY,
PP.FULL_NAME ,
M.TRANSACTION_QUANTITY
FROM MTL_TXN_REQUEST_HEADERS RH,
MTL_TXN_REQUEST_LINES RL,
MTL_SYSTEM_ITEMS_KFV MSIK,
FND_USER FU,
PER_PEOPLE_V7 PP,
( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE, SUM(MOQ.TRANSACTION_QUANTITY)
FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
AND MSIK2.ORGANIZATION_ID = 8
AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
WHERE
RH.HEADER_STATUS IN(3,7,8)
AND RH.MOVE_ORDER_TYPE IN(1,2)
and rh.header_id = rl.header_id
AND MSIK.INVENTORY_ITEM_ID = RL.INVENTORY_ITEM_ID
AND MSIK.ORGANIZATION_ID = 8
AND RL.FROM_SUBINVENTORY_CODE LIKE 'ST%'
AND RH.CREATED_BY = FU.USER_ID
AND FU.EMPLOYEE_ID = PP.PERSON_ID
However, when I try to run I got the invalid column for m.transaction_quantity ??? why? does it b'cos of the group sum that I used ?
My intention of this query to display the sum of total qty from the mtl_onhand_quantities table.
Please helps.
Thanks.
Rgds
Limsorry if its too late.....
my guess is alias the SUM(MOQ.TRANSACTION_QUANTITY) in the sub-query table (M) as TRANSACTION_QUANTITY.
-------- code snippet---------
FND_USER FU,
PER_PEOPLE_V7 PP,
( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE,
SUM(MOQ.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY <------------------------------------This is important
FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
AND MSIK2.ORGANIZATION_ID = 8
AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
WHERE
RH.HEADER_STATUS IN(3,7,8)
AND RH.MOVE_ORDER_TYPE IN(1,2)
--------------code snippet ends------------------------
hope this helps, -
I am struck up with the sql query pleas help me
Hi,
i am struck up with this query
select cpuid,hostid,timestamp from
system_Cpu
where hostid='dscp02469' AND cpuid='second'
CPUID HOSTID TIMESTAMP
second dscp02469 29:jun:2006:18:30:18
second dscp02469 29:jun:2006:18:31:04
second dscp02469 29:jun:2006:18:32:53
second dscp02469 29:jun:2006:18:40:39
second dscp02469 29:jun:2006:18:41:26
second dscp02469 29:jun:2006:18:42:31 (top entry)
i have to get top five minutes records
CPUID HOSTID TIMESTAMP
second dscp02469 29:jun:2006:18:40:39
second dscp02469 29:jun:2006:18:41:26
second dscp02469 29:jun:2006:18:42:31
i am writing this query
select cpuid,hostid,timestamp from system_Cpu where hostid='dscp02469' AND cpuid='second' having max(timestamp)-timestamp<5/1440
having max(timestamp)-timestamp<5/1440
ERROR at line 2:
ORA-00979: not a GROUP BY expression
Message was edited by:
user517983You seem to be offended...
Well, here is what I tried out (and then posted)...
SQL> select cpuid,hostid,to_char(timestamp, 'dd/mon/yyyy hh24:mi:ss') FROM(select cpuid,hostid,times
tamp, max(timestamp) over () maxts from system_Cpu where hostid='dscp02469' AND cpuid='second' )WHER
E maxts-timestamp<5/1440 ;
CPUID HOSTID TO_CHAR(TIMESTAMP,'D
second dscp02469 29/jun/2006 18:40:39
second dscp02469 29/jun/2006 18:41:26
second dscp02469 29/jun/2006 18:42:31And just to display time component, I modified it a bit...
SQL> select cpuid,hostid,to_char(timestamp, 'dd/mon/yyyy hh24:mi:ss') FROM(select cpuid,hostid,times
tamp, max(timestamp) over () maxts from system_Cpu where hostid='dscp02469' AND cpuid='second' )WHER
E maxts-timestamp<5/1440 ;
CPUID HOSTID TO_CHAR(TIMESTAMP,'D
second dscp02469 29/jun/2006 18:40:39
second dscp02469 29/jun/2006 18:41:26
second dscp02469 29/jun/2006 18:42:31It worked for me. BTW, the way I interpreted the OP's requirement was-give all records that are within 5 minutes interval from the top (or max) timestamp.
I may be wrong...
Maybe you are looking for
-
How do I attach a picture in iPhoto to an email? I can't find it anywhere else.
How can I attach a picture in iPhototo a gmail? I can't find the picture anywhere else on my computer.
-
Creating mysql schema from pojo with hibernate using netbeans
I have been fortunate in finding some good tutorials on how to create POJOs from database schema using hibernate (e.g. http://netbeans.org/kb/docs/web/hibernate-webapp.html). Does anyone know of tutorials on creating database schemas from POJOs -- pr
-
Camera raw plug in para nikon d800e
Tengo Lightroom 3.6 con Camera Raw 6.6. Acabo de leer aquí que necesito una versión superior que soporte los archivos raw de nikon d800e ¿no existe una actualización del plug-in? Me gustaría poder seguir utilizando LR y PS adquiridos hace no mucho,
-
Why does my iphone not show in tunes when on same wireless network
why does my ipad, and my two iphones not show in itunes on the same wireless network
-
Where is the $2 coupon for the CD - Spoon - They Want My Soul?
where is the $2 coupon for the CD - Spoon - They Want My Soul?