Help needed in writing query
Hi,
Could anyone help me in writing below query without syntax errors.
I tried but no luck
select xmlelement("g", XMLATTRIBUTES(g.contentgroup_id as "id",g.groupname as "label",
(select xmlagg(xmlelement ("c",XMLATTRIBUTES(c.title as "title",c.content_id as "id")))) as "A"))
as "A" from
(SELECT g.contentgroup_id AS id, g.groupname AS label, c.title AS label, c.content_id AS id
FROM content_ec c FULL OUTER JOIN contentgroup_ec g ON c.group_id = g.contentgroup_id
oRDER BY g.groupname ,c.title ASC );
Any help really appreciated.
Thanks
Few tips to get your question answered here
1. Give your database version. Some thing that does not work in one version works fine in the next. And 8i,9i or 10g is not version. best way to give the version is to query your v$version table like this.
SQL> select * from v$version where rownum = 1
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod2. You should understand we don't have what you have, meaning you should provide your data structure and some sample data for us to help.
3. "I got an error"... "Its not working"... and the list goes on. Sentences like this does not help. If you got a error past the entire error. If stuff does not work, tell us the details.
4. Just don't throw some output and say i want it. Please explain to every one how you derive it.
5. And the most important thing. Use \...\ tag to format. Please.. Please.. Please.. use it. It helps every one a lot. When you use it your SQL looks some thing like this.
SELECT xmlelement("g", XMLATTRIBUTES(g.contentgroup_id as "id",g.groupname as "label",
(select xmlagg(xmlelement ("c",XMLATTRIBUTES(c.title as "title",c.content_id as "id")))) as "A")) as "A"
FROM (SELECT g.contentgroup_id AS id,
g.groupname AS label,
c.title AS label,
c.content_id AS id
FROM content_ec c
FULL OUTER JOIN contentgroup_ec g
ON c.group_id = g.contentgroup_id
ORDER BY g.groupname ,c.title ASC );6. And also do search this forum. Most of your my queries are answered by simple search.
Thanks,
Karthick.
Similar Messages
-
help needed for writing query
i have the following tables(with data) as mentioned below
FK*-foregin key (SUBJECTS)
FK**-foregin key (COMBINATION)
1)SUBJECTS(table name)
SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
2 02 Computer Science
3 03 Physics
4 04 Chemistry
5 05 Mathematics
7 07 Commerce
8 08 Computer Applications
9 09 Biology
2)COMBINATION
COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
383 S1 9 4 2 3
384 S2 4 2 5 3
---------I actually designed the ABOVE table also like this
3) a)COMBINATION
COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
383 S1
384 S2
b)COMBINATION_DET
COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
1 383 9
2 383 4
3 383 2
4 383 3
5 384 4
6 384 2
7 384 5
8 384 3
Business rule: a combination consists of a maximum of 4 subjects (must contain)
and the user is less relevant to a COMB_NAME(name of combinations) but user need
the subjects contained in combinations
i need the following output
COMB_ID COMB_NAME SUBJECT1 SUBJECT2 SUBJECT3 SUBJECT4
383 S1 Biology Chemistry Computer Science Physics
384 S2 Chemistry Computer Science Mathematics Physics
or even this is enough(what i actually needed)
COMB_ID subjects
383 Biology,Chemistry,Computer Science,Physics
384 Chemistry,Computer Science,Mathematics,Physics
you can use any of the COMBINATION table(either (2) or (3))
and i want to know
1)which design is good in this case
(i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
good method to link with same table but if 4 subjects only(and must) comes
detail table is not neccessary )
now i am achieving the result by program-coding in C# after getting the rows from oracle
i am using oracle 9i (also ODP.NET)
i want to know how can i get the result in the stored procedure itsef.
2)how it could be designed in any other way.
any help/suggestion is welcome
thanks for your time --PradeeshWell I forgot the table-alias, here now with:
SELECT C.COMB_ID
, C.COMB_NAME
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
FROM COMBINATION C;
As you need exactly 4 subjects, the columns-solution is just fine I would say. -
Help needed in writing a function.
I am using Oracle 11g and SQL plus. I am a complete newbie, so I need some help here in writing a function. I guess my question is more about writing the trigonometric functions within the function.
latA, longA latB, longB // these are the four input parameters,
theta = longA - longB
distX = sin( latA * PI / 180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180)
distY = acos(distX) // this is arc cosine
distZ = distY * 180 / PI // PI refers to the mathematical PI
distP = distZ * 60 * 1.1515; // this value should be returned. Of course the intermediate variable names don't matter.
Please help. Thanks.CREATE OR REPLACE FUNCTION fucntion_name(latA IN NUMBER, longA IN NUMBER, latB IN NUMBER, longB IN NUMBER) RETURN NUMBER
IS
pi CONSTANT NUMBER:=3.14159;
theta NUMBER;
distX NUMBER;
distY NUMBER;
distZ NUMBER;
distP NUMBER;
BEGIN
theta :=longA - longB;
distX :=sin( latA * PI /180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180);
distY :=acos(distX); --this is arc cosine
distZ :=distY * 180/PI; --PI refers to the mathematical PI
distP :=distZ * 60 * 1.1515; --this value should be returned. Of course the intermediate variable names don't matter.
RETURN distP;
END;Edited by: Ora on May 3, 2011 11:46 PM -
Could you please help me in writing query
Hi,
Data in table
ID -- H_squ -- D_squ --- Note
0001 1 1 he is
0001 1 2 coming
0001 1 3 from US
0001 2 2 he is going
0001 2 5 Back to US
0002 1 3 he took
0002 1 2 his laguage
0002 2 3 bi
output shouldbe
ID -- H_squ -- D_squ --- Note
<0001> <1> <1,2,3> <he is coming from US>
<0001> < 2 > <2,5> < he is going Back to US>
<0002> <1> <3,2> <he took his laguage>
<0002> <2> <3> <bi>
Actually I used STRAGG function But i am not getting expected output
group by ID, H_squ concat data order by D_squ column
Note should contain concat of D_squ(1,2,3) in this order
Could you please help me in writing queryThis forum is for issues related to Advanced Queuing.
Please only post in forums where your questions are appropriate. -
Help needed in writing a Query/Procedure
Hello All,
Need all ur help in writing a query or procedure
Lets say the Table name is DEMO
There i have one column like num it has values
1
2
3
4
5
8
9
10
my query output should be
1-5
8-10
i,e .. if the diff between two rows is greater than 1 then it result should be in a separate group
I need a query/Procedure for this. Kindly help
Regards,
ChandraTried obtaining the output using SQL and the result is as follows:
SQL> WITH T AS
2 (
3 SELECT 1 COL1 FROM DUAL
4 UNION
5 SELECT 2 COL1 FROM DUAL
6 UNION
7 SELECT 3 COL1 FROM DUAL
8 UNION
9 SELECT 4 COL1 FROM DUAL
10 UNION
11 SELECT 5 COL1 FROM DUAL
12 UNION
13 SELECT 8 COL1 FROM DUAL
14 UNION
15 SELECT 9 COL1 FROM DUAL
16 UNION
17 SELECT 10 COL1 FROM DUAL
18 UNION
19 SELECT 13 COL1 FROM DUAL
20 UNION
21 SELECT 14 COL1 FROM DUAL
22 UNION
23 SELECT 15 COL1 FROM DUAL
24 UNION
25 SELECT 16 COL1 FROM DUAL
26 UNION
27 SELECT 23 COL1 FROM DUAL
28 UNION
29 SELECT 24 COL1 FROM DUAL
30 )
31 SELECT OUTPUT FROM
32 (
33 SELECT DECODE(COL3,NULL,COL1, COL2) || '-' || LEAD(DECODE(COL3,NULL,COL3, COL1)) OVER (ORDER BY DECODE(COL3,NULL,COL1, COL2)) OUTPUT FROM
34 (
35 SELECT COL1, LEAD(COL1) OVER (ORDER BY COL1) COL2, LAG(COL1) OVER (ORDER BY COL1) COL3 FROM T
36 )
37 WHERE
38 (COL2 - COL1 > 1 OR COL2 IS NULL OR COL3 IS NULL)
39 )
40 WHERE OUTPUT != '-';
OUTPUT
1-5
8-10
13-16
23-24 -
Help needed in writing a query
Hi all,
Following is the structure of my table.
Data
Key Number
Id Number
Value varchar2(100)
activity_name varchar2(100)
Creation_Date Date
Eval_Point varchar2(100)
In the above table Id is the primary key.
The column eval_point holds only two types of entries 'activation' or 'completion'
The activity_name column holds the name of the activity.
The sample entries in the table are as follows
Key Value activity_name Creation_Date Id Eval_Point
260002 XXX assign_1 2007-09-21 16:58:41.920000 951 activation
260002 XXX assign_1 2007-09-21 16:58:43.392000 953 completion
260002 XXX assign_2 2007-09-21 16:59:03.732000 956 activation
260002 XXX assign_2 2007-09-21 16:59:04.112000 954 completion
260002 XXX assign_3 2007-09-21 16:59:24.331000 958 activation
260002 XXX assign_3 2007-09-21 16:59:24.421000 957 completion
i need to write a query which gives me data in the following format
value id start_date end_date
XXX YYY 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000
where start_date is the creation date of the 'activation' and end_date is the creation_date of 'completion'.
Can somebody help?
-thanks
lavanyahello all,
I would like to re frame my question.
this is the output of the base query
select id,instance_key,sensor_target,activity_sensor,creation_date,eval_point from bpel_variable_sensor_values where instance_key=260002;
953 260002 Assign_1 952 2007-09-21 16:58:43.392000 completion
951 260002 Assign_1 952 2007-09-21 16:58:41.920000 activation
956 260002 Assign_2 955 2007-09-21 16:59:03.732000 activation
954 260002 Assign_2 955 2007-09-21 16:59:04.112000 completion
958 260002 Assign_3 959 2007-09-21 16:59:24.331000 activation
957 260002 Assign_3 959 2007-09-21 16:59:24.421000 completion
962 260002 Assign_4 960 2007-09-21 16:59:44.741000 completion
961 260002 Assign_4 960 2007-09-21 16:59:44.640000 activation
964 260002 Assign_5 965 2007-09-21 17:00:05.290000 completion
963 260002 Assign_5 965 2007-09-21 17:00:04.950000 activation
I am trying out this query
select a.instance_key,a.creation_date,b.creation_date,a.id
from bpel_variable_sensor_values a, bpel_variable_sensor_values b
where a.instance_key=b.instance_key
and a.instance_key=260002
and a.eval_point='activation'
and b.eval_point='completion'
and i am getting 25 entries i.e a cartesian product of a.creation_date
260002 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:04.112000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:24.421000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:44.741000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 17:00:05.290000 951
260002 2007-09-21 16:59:03.732000 2007-09-21 16:58:43.392000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:04.112000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:24.421000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:44.741000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 17:00:05.290000 956
260002 2007-09-21 16:59:24.331000 2007-09-21 16:58:43.392000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:04.112000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:24.421000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:44.741000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 17:00:05.290000 958
260002 2007-09-21 16:59:44.640000 2007-09-21 16:58:43.392000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:04.112000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:24.421000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:44.741000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 17:00:05.290000 961
260002 2007-09-21 17:00:04.950000 2007-09-21 16:58:43.392000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:04.112000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:24.421000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:44.741000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 17:00:05.290000 963
can soembody help me to reduce these to 5 rows. -
Help needed on writing a SQL query
Here is my table that shows records of 3 ORDER_ID (10, 20 and 30). All I need to do is, pick the first record of each order_id and check the event_id, if the event_id is same for the next record, ignore it, else show it and ignore rest all records for that order_id. This way my query output will show only two records for each ORDER_ID. Query should produce records that are in BOLD in the sample data. (Database - 11g)
Thanks for your help in advance
ORDER_ID EVENT_ID EVNT_DATE STATE_CODE
*10 16937555 20100212 COMPLETE*
10 16937555 20100212 ACTIVE
*10 16308004 20100129 OCCURRED*
10 16131904 20100125 ACTIVE
10 16270684 20100128 OCCURRED
10 14899116 20091213 ACTIVE
10 16085672 20100123 COMPLETE
10 16085673 20100123 OCCURRED
10 14899119 20100123 COMPLETE
10 14899120 20100123 COMPLETE
*20 17134164 20100223 COMPLETE*
20 17134164 20100223 ACTIVE
20 17134164 20100223 STARTED
*20 15479131 20100105 OCCURRED*
20 15478409 20100105 OCCURRED
20 15478408 20100105 ACTIVE
20 15119404 20100105 COMPLETE
20 14346123 20091129 ACTIVE
20 15467821 20100104 OCCURRED
20 14346125 20091216 COMPLETE
20 14346126 20091215 COMPLETE
20 14346126 20091214 COMPLETE
*30 18814670 20100412 COMPLETE*
30 18814670 20100412 ACTIVE
*30 18029509 20100320 OCCURRED*
30 16853720 20100211 ACTIVE
30 17965764 20100319 OCCURRED
30 16386708 20100211 COMPLETE
30 16804451 20100211 OCCURRED
30 15977897 20100121 ACTIVE
Edited by: sarvan on Aug 12, 2011 7:16 AMtry this [Not fully tested]
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Elapsed: 00:00:00.00
SQL> SELECT *
2 FROM (SELECT order_id, event_id, evnt_date, state_code, next_evntid,
3 ROW_NUMBER () OVER (PARTITION BY event_id ORDER BY NULL)
4 AS rownm
5 FROM (WITH t AS
6 (SELECT 10 AS order_id, 16937555 AS event_id,
7 20100212 AS evnt_date, 'COMPLETE' AS state_code
8 FROM DUAL
9 UNION ALL
10 SELECT 10, 16937555, 20100212, 'ACTIVE'
11 FROM DUAL
12 UNION ALL
13 SELECT 10, 16308004, 20100129, 'OCCURRED'
14 FROM DUAL
15 UNION ALL
16 SELECT 10, 16131904, 20100125, 'ACTIVE'
17 FROM DUAL
18 UNION ALL
19 SELECT 10, 16270684, 20100128, 'OCCURRED'
20 FROM DUAL
21 UNION ALL
22 SELECT 20, 17134164, 20100223, 'COMPLETE'
23 FROM DUAL
24 UNION ALL
25 SELECT 20, 17134164, 20100223, 'ACTIVE'
26 FROM DUAL
27 UNION ALL
28 SELECT 20, 17134164, 20100223, 'STARTED'
29 FROM DUAL
30 UNION ALL
31 SELECT 20, 15479131, 20100105, 'OCCURRED'
32 FROM DUAL) -- End of test data
33 SELECT order_id, event_id, evnt_date, state_code,
34 LEAD (event_id, 1, 0) OVER (PARTITION BY order_id ORDER BY NULL)
35 AS next_evntid
36 FROM t)
37 WHERE event_id = next_evntid)
38 WHERE rownm <= 2
39 /
ORDER_ID EVENT_ID EVNT_DATE STATE_CO NEXT_EVNTID ROWNM
10 16937555 20100212 COMPLETE 16937555 1
20 17134164 20100223 COMPLETE 17134164 1
20 17134164 20100223 ACTIVE 17134164 2
Elapsed: 00:00:00.00
SQL> PS - You should seriously think about ordering the data before you do this kind off operations.
Edited by: Sri on Aug 12, 2011 9:12 AM -
Help needed for writing a Query.
I want to write a query in SSRS, SQL Server 2012, Report Builder 3.0. There is 3 tables as follows
Table A
ID Name
1 AAAAA
2 BBBBB
Table B
ID BS
1 5000
2 3000
Table C
ID Allowance
Amt
1 HRA
500
1 TA
200
2 HRA
300
Output Expected
ID Name
BS HRA
TA
1 AAAAA
5000 500
200
2 BBBBB
3000 300
0
ShareefThis is the result from the above code:
id Name BS Allowance TA
1 AAAAA 5000 500 200
2 BBBBB 3000 300 0
Please mark this reply as answer if it solved your issue or vote as helpful if it helped.
[Blog]
But I am getting something like this.
id
Name BS Allowance TA
1
AAAAA 5000 500
1
AAAAA
200
2 BBBBB
3000 300 0
Shareef -
CREATE TABLE S1(ID VARCHAR2(10), CAT_CODE NUMBER, CAT VARCHAR2(10))
CREATE TABLE S2(ID VARCHAR2(10),NUM NUMBER,DESCRIPTION VARCHAR2(10))
INSERT INTO S1 VALUES('2-1',NULL,'BUSINESS')
INSERT INTO S2 VALUES('3-1',10,'BUSINESS')
SELECT A.ID,B.ID FROM S1 A,S2 B WHERE A.CAT_CODE=B.NUM(+) AND A.CAT=B.DESCRIPTION(+)
OUTPUT IS : 2-1 BLANK
SELECT A.ID,B.ID FROM S1 A,S2 B WHERE A.CAT_CODE(+)=B.NUM AND A.CAT(+)=B.DESCRIPTION
OUTPUT IS : BLANK 3-1
IF I WANT THE OUTPUT TO BE
2-1 3-1 HOW SHALL I WRITE THE QUERY
I TRIED WITH UNIONPlease read my query if your table is not having any common data field.
select a.employee_code,b.employee_Code from
(select rownum srno,employee_code from pms_employee_master
where company_code=48 and category_code='01') a,
(select rownum srno1,employee_code from pms_employee_master
where company_code=48 and category_code='01') b
where a.srno=b.srno1
Above I am using my one table with rownum u can user different tables for this purpose.
Thx
Shishu Paul -
hello ,
I am a beginner in terms of writing sql queries. I hope some body can help me out.
I have two tables
mysql> desc user_group_t;
---------------------------------------------------+
| Field | Type | Null | Key | Default | Extra |
---------------------------------------------------+
| userAccountId | char(8) | | PRI | | |
| groupId | char(8) | | PRI | | |
---------------------------------------------------+
2 rows in set (0.00 sec)
mysql> desc group_t;
---------------------------------------------------+
| Field | Type | Null | Key | Default | Extra |
---------------------------------------------------+
| id | char(8) | | PRI | | |
| name | char(50) | YES | | NULL | |
| email | char(100) | YES | | NULL | |
| description | char(254) | YES | | NULL | |
| parentId | char(8) | YES | | NULL | |
| creatorId | char(8) | YES | | NULL | |
| createDate | char(20) | YES | | NULL | |
| updateDate | char(20) | YES | | NULL | |
| updatorId | char(8) | YES | | NULL | |
---------------------------------------------------+
9 rows in set (0.00 sec)
what I want is list of all groups with id,name and #of members(which is the # of rows in the user_group_t for any given id). Importantly I need the groups with 0 members also to be listed. In short my output should contain exactly the same number of rows as in group_t table with an additional column indicating # of members for that group.
Any help would be greatly appreciated.
Thanks in Advance.
-VasanthThanks Donald,
Actually I figured it out, with the following query:
select id,name,sum(if(groupid is not null,1,0)) as members from group_t left join user_group_t on id=groupid group by id;
I tried your solution, but mysql says there is an error at '+' . Anyway I modified your solution to the one below and it worked.
select a.id, a.name, count(b.groupid) from group_t a left join user_group_t b on a.id=b.groupid group by a.id, a.name;
I tried that before but then I used Count(*) instead of count on groupid. Your solution is elagant and I will go with yours.
Thanks again.
Vasanth -
Hello All,
I have just started working in PL/SQL,
I need some help on 1 urgent issue.
i have a table lets say which has structure and values like below:
ID Data Key Data Value
1 Firstname X
2 Lastname Y
3 Middlename Z
but my query shd return me data having firstname ,middlenale and last name as column names and lvalues like lsited below:
Firstname Middlename Lastname
X Y Z
Please help and i really appreciate for your time and help!!!!!!!!!!
Thanks and RegardsUrgent? I don't think so.
However, as others have mentioned, what groups the items together so that the relationship is known between them?
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as id, 'Firstname' as data_key, 'Fred' as data_val from dual union all
2 select 2, 'Surname', 'Bloggs' from dual union all
3 select 3, 'Middlename', 'J' from dual union all
4 select 4, 'Firstname', 'John' from dual union all
5 select 5, 'Surname', 'Doe' from dual union all
6 select 6, 'Middlename', 'D' from dual)
7 --
8 select id-decode(data_key,'Surname',1,'Middlename',2,0) as id
9 ,max(decode(data_key,'Firstname',data_val)) as Firstname
10 ,max(decode(data_key,'Middlename',data_val)) as Middlename
11 ,max(decode(data_key,'Surname',data_val)) as Surname
12 from t
13* group by id-decode(data_key,'Surname',1,'Middlename',2,0)
SQL> /
ID FIRSTN MIDDLE SURNAM
1 Fred J Bloggs
4 John D Doe
SQL>This example assumes that a Firstname, Surname and Middlename appear in that order with sequential ID's, such that the ID for Surname is always 1 more than the ID for it's associated Forename and the ID for Middlename is always 2 more than the associated Forename. -
Hi,
I need to select the max time for the transaction using the below query. I’m able to get the o/p. Here the problem is I need to fetch the corrletorid (primary key) as well. if try to get that I’m getting the o/p like case2.
I want the o/p to be like case 1 with the corrleator id . plz help me to get the o/p.
Case 1: select b.TransactionName, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname
TRANSACTIONNAME MAXTIME
FINT3 12/10/2007 19:53:09.042000
FINT 12/10/2007 19:31:07.042000
FINT2 12/10/2007 19:31:07.042000
SQL> /
Case 2: select b.TransactionName,b.correlatorid, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname,b.correlatorid
SQL> /
TRANSACTIONNAME CORRELATORID AVERAGE
FINT2 102 12/10/2007 19:31:07.042000
FINT3 108 12/10/2007 19:53:09.042000
FINT3 103 12/10/2007 19:31:07.042000
FINT 101 12/10/2007 19:31:07.042000
in the above output i should have only record(max time) for FINT3.
ThankSharma,
Please find the below sample data(insert stmt and create table):
======================================
create table trandetails(
correlatorid varchar2(20) CONSTRAINT correlatorid_FKey REFERENCES Subtrandetails(correlatorid),
username varchar2(25) NOT NULL,
applicationname varchar2(25) NOT NULL,CONSTRAINT composite1_pkey1 PRIMARY KEY(correlatorid ,applicationname));
create table Subtrandetails(
correlatorid varchar2(20) PRIMARY KEY,
PCORRELATORID varchar2(20),
TransactionName varchar2(25) NOT NULL,
Machinename varchar2(15) NOT NULL,
STARTDATE timestamp NOT NULL,
ENDDATE timestamp NOT NULL,
SourceName varchar2(25),
FunctionName varchar2(25),
LOC number(5),
CONTEXTPROPERTY1 varchar2(25),
CONTEXTPROPERTY2 varchar2(25),
CONTEXTPROPERTY3 varchar2(25),
TransactionStatus varchar2(25) NOT NULL CONSTRAINT Transaction1_Status_chk Check (TransactionStatus in ('Success', 'Failure', 'Abort')));
INSERT INTO trandetails VALUES ('11','FINAPP','ANUAPP1');
INSERT INTO trandetails VALUES ('13','FINTEST','ANUAPP2');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('10','1','ARM','blrkec95931d','10-DEC-07 03.24.07.042000 PM','10-DEC-07 03.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('11','1','ARM1','blrkec95931d','10-DEC-07 04.24.07.042000 PM','10-DEC-07 04.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('12','1','ARM2','blrkec95931d','10-DEC-07 05.24.07.042000 PM','10-DEC-07 05.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('13','1','ARM3','blrkec95931d','10-DEC-07 06.24.07.042000 PM','10-DEC-07 06.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('14','1','ARM4','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('101','11','FINT','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('102','11','FINT2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('103','11','FINT3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('104','13','SAP1','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('105','13','SAP2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('106','13','SAP3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('107','13','SAP2','blrkec95931d','10-DEC-07 07.2.10.042350 PM','10-DEC-07 07.50.10.042050 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('108','11',' FINT3 ','blrkec95931d','10-DEC-07 07.16.07.042000 PM','10-DEC-07 07.53.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('109','108','FINT3','blrkec95931d','10-DEC-07 07.20.07.042000 PM','10-DEC-07 07.59.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('110','108','FINT3','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('111','108','FINT4','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('112','108','FINT5','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('113','108','FINT6','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('114','108','FINT7','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
======================================
Thanks. -
Help needed in writing a procedure
Guys, i need some more help.
I am selecting one value using select by passing a parameter to that select statement which are stored in a file using utl_file package.
Now, I want to use the output of that query and use that value to update a column in the same table.
for ex:-
select comm from emp where empno = &empno1;
I want to use the comm value and update the comm value.
update emp
set comm = comm + 10
where empno = &empno1
Help Appreciated
ThanksSQL> desc emp
Name Null? Type
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
NET_SALARY NUMBER(12,2)
SQL> select salary,COMMISSION_PCT,net_salary from emp where employee_id = 198;
SALARY COMMISSION_PCT NET_SALARY
2600 .1
SQL> update emp
2 set net_salary = salary + (select COMMISSION_PCT from emp where employee_id = &&empno)*salary
3 where employee_id = &&empno
4 /
Enter value for empno: 198
old 2: set net_salary = salary + (select COMMISSION_PCT from emp where employee_id = &&empno)*salary
new 2: set net_salary = salary + (select COMMISSION_PCT from emp where employee_id = 198)*salary
old 3: where employee_id = &&empno
new 3: where employee_id = 198
1 row updated.
SQL> select salary,COMMISSION_PCT,net_salary from emp where employee_id = 198;
SALARY COMMISSION_PCT NET_SALARY
2600 .1 2860
Hope this helps; -
I have a table TAB that has two colums. COL1 and COL2. Both are composite Primary key.
The data is as
COL1 COL2
1 C
2 C
3 C
4 G
5 G
1 G
3 G
6 G
7 G
I need to find out those COL1 values whose COL2 values are C and G. Ex
COL1 COL2
1 C
3 C
1 G
3 G
So i need the following op
COL1
1
3
Please help me to solve this query.
Regards.
Message was edited by:
SIDand what have you tried ????
SQL> With t As
2 (
3 Select 1 c1, 'C' c2 From DUAL Union All
4 Select 2, 'C' From DUAL Union All
5 Select 3, 'C' From DUAL Union All
6 Select 4, 'G' From DUAL Union All
7 Select 5, 'G' From DUAL Union All
8 Select 1, 'G' From DUAL Union All
9 Select 3, 'G' From DUAL Union All
10 Select 6, 'G' From DUAL Union All
11 Select 7, 'G' From DUAL
12 )
13 Select t.c1, t.c2
14 From
15 t,
16 (
17 Select c1, c2
18 From t
19 Where c2 = 'C'
20 ) c,
21 (Select c1, c2
22 From t
23 Where c2 = 'G'
24 ) g
25 Where t.c1 = c.c1
26 And t.c1 = g.c1
27 --And c.c2 = g.c2;
C1 C2
1 C
1 G
3 C
3 G
SQL>
/*using analytical functons*/
SQL>
SQL> With t As
2 (
3 Select 1 c1, 'C' c2 From DUAL Union All
4 Select 2, 'C' From DUAL Union All
5 Select 3, 'C' From DUAL Union All
6 Select 4, 'G' From DUAL Union All
7 Select 5, 'G' From DUAL Union All
8 Select 1, 'G' From DUAL Union All
9 Select 3, 'G' From DUAL Union All
10 Select 6, 'G' From DUAL Union All
11 Select 7, 'G' From DUAL
12 )
13 select c1, c2
14 from ( select c1,c2, case when c2 = 'C' then count(decode(c2,'G',1)) over (partition by c1)
15 when c2 = 'G' then count(decode(c2,'C',1)) over (partition by c1)
16 else 0 end count
18 from t
19 )
20 where Count != 0
21 /
C1 C2
1 C
1 G
3 C
3 GMessage was edited by:
Nicloei W -
Hi,
I need to display the parent child nodes in the hierarchical manner and i need to list the user under their hier name in the same hierarchical structure. table structures are all as follows.
user table:
* userid name*
100 john
101 shaddy
102 sandy
103 Kalinich
104 king
105 Teresa
106 Clinia
user hier table :
userid hier name
100 node1
101 node2
102 node1
103 node2
104 parent
105 node4
106 node
hier table:
id hier name parent_id
1 parent
2 node 1
3 node1 2
4 node2 2
5 node3 1
6 node4 5
7 node5 5
o/p :
104 king
106 clinia
100 john
102 sandy
103 Kalinich
101 shaddy
105 terresa
even we dont have entry in user hier and user table for node3 we need to display them child users under the "parent" hier name and need to ignore the child nodes which dont have users under them i.e) need to ignore node5 in the output. below is the query which I have tried.
SELECT NAME,u.name
FROM user_hier n,hier u,user a
WHERE a.user_id (+) = u.user_id
AND u.name (+) = n.name
START WITH n.name = 'parent'
CONNECT BY PRIOR n.node_id= n.parent_node_id;
Help me on this.
Thanks in advance
Edited by: Vi on Apr 30, 2012 6:10 AMNo you haven't. Either post create table statements or set up your data with a WITH clause, something like the following example:
with USER_TABLE as (
select 100 userid, 'john' name from dual union all
select 101 userid, 'shaddy' name from dual union all
select 102 userid, 'sandy' name from dual union all
select 103 userid, 'Kalinich' name from dual union all
select 104 userid, 'king' name from dual union all
select 105 userid, 'Teresa' name from dual union all
select 106 userid, 'Clinia' name from dual
select * from USER_TABLE
USERID NAME
100 john
101 shaddy
102 sandy
103 Kalinich
104 king
105 Teresa
106 Clinia
7 rows selected.
Maybe you are looking for
-
Where to control and give error message before saving trade promotion?
Hi Gurus, our CRM system is upgraded from 5.0 to 7.0 and we have some problems. One of them is, in 5.0 version, we check some conditions and display error message in the AUTHORITY_CHECK method of CRM_MKTPL. So the check is made and message displayed
-
Dear All, I am using InfoCube 0IC_C03 in BI 7 and I found that there are InfoSources for this cube such as 2LIS_03_BX_TR. I just want to know what the different and its features between 2LIS_03_BX_TR and the previous version 2LIS_03_BX. Could anyone
-
Dear Gurus, Kindly guide me. my requirement is : Highlight text in pdf -----> should be pasted in Word using a macro/hotkey i.e automatically is this possible? or any other procedure so that a group of text in different paragraph in pdf can automatic
-
Color ( or motion) on second computer - different mac than Final Cut
Hi, is there a way to install e.g. color or motion on a second computer and have Final Cut Pro send the clip/clips there for grading and back? Or does the 'send to color' only work for 1 mac? Thanks, Robert FCS2 in intel Macbook Pro Mac OS X (10.4.
-
Evaluate, Time Sync, and merge 2 arrays into 1
I have two separate text files I am reading in to be processed within Labview. I read these two files in and convert them each into 2D arrays. What I need to do is to evaluate these files and syncronize times which are in the first column line by lin