Help required in writing an sql querry
Hi guys,
Could any one hlep me out in writing an sql querry for the below requirement.
the requirement is: for a perticular ID if we have different names then we need to get it out as multiple else the name itselef. I have given the sample input and the expected output.
ID Name
1 A
1 B
2 F
2 F
3 C
4 D
4 E
Out put should look like
ID Name
1 Multiple
2 F
3 C
4 Multiple
Thanks in advance
Shylender.
Edited by: 959345 on Nov 22, 2012 10:13 PM
May be this:
WITH t AS
(SELECT 1 id, 'A' str FROM DUAL
UNION ALL
SELECT 1, 'B' FROM DUAL
UNION ALL
SELECT 2, 'F' FROM DUAL
UNION ALL
SELECT 2, 'F' FROM DUAL
UNION ALL
SELECT 3, 'C' FROM DUAL
UNION ALL
SELECT 4, 'D' FROM DUAL
UNION ALL
SELECT 4, 'E' FROM DUAL),
t1 AS
(SELECT id,
CASE
WHEN COUNT (DISTINCT str) OVER (PARTITION BY id) > 1 THEN
'MULTIPLE'
ELSE
str
END
str
FROM t)
SELECT id, str
FROM t1
GROUP BY id, str
ORDER BY 1;Cheers,
Manik.
Similar Messages
-
Help required in writing an sql to fetch the the difference of the data.
Hi Gurus,
Could some one help me in writing an sql to pull data the difference between two same structured tables from two different database and to store that data in an temperory table.
many many thanks in advanceLets say you have two db SOURCE and DEST
SOURCE is the DB that you have Logged in into. Now you do the following.
1. Createa DBLink to DEST database.
2. Check if the DBLink works properly.
3. Then execute the following sql.
select <column_list> from <table_name>
minus
select <column_list> from <table_name>@<dblink>
union all
select <column_list> from <table_name>@<dblink>
minus
select <column_list> from <table_name> -
Please help me in writing the SQL
Hi,
I am new to oracle.. Can you please help me in writing a SQL
I have a table which has the following columns
Start_date m1 ---- Start month of each quarter (Jan,Apr,Jul,oct)
end_date m3---- End month of each quarter
m1_start_date,
m1_end_date,
m2_start_date,
m2_end_date,
m3_start_date,
m3_end_date,
M1_act_rev,
m2_act_rev,
m3_act_rev
If a user selects the dates from Jan,2011 to Jun, 2011
I should get the aggregate of the revenues (m1+m2+m3+m1+m2+m3)Hi Gurus,
Will this work
select
b.DISTRICT_NAME,
count(c.CONTRACT_NUMBER),
sum(C.M1_ACT_REV),
sum(C.M2_ACT_REV),
sum(C.M3_ACT_REV),
sum(C.M1_EXP_PRICE),
sum(C.M2_EXP_PRICE),
sum(C.M3_EXP_PRICE)
from
clm_mn_compliance_data c,
CLM_MN_CUSTOMER_ALIGNMENT_DATA b
where
((m1_start_date between '01-01-2011' and '03-31-2011' ) and (m1_end_date between '01-01-2011' and '03-31-2011')) or
((m2_start_date between '01-01-2011' and '03-31-2011' ) and (m3_end_date between '01-01-2011' and '03-31-2011')) or
((m3_start_date between '01-01-2011' and '03-31-2011' ) and (m3_end_date between '01-01-2011' and '03-31-2011')) and
b.CUSTOMER_ID = C.CUST_CTRT_ID
group by
B.DISTRICT_NAME; -
Help required in writing And Reading Xml From Database
Hi
i m new to java.
i m facing problem while writing Xml file from Mysql Database in java i m using the WebRowSet
and also for Reading WebRowSet
after reading the Xml i have to save this in Database
(required source code)
is there any one to help me in this way
regards
aamirshadab_think_globally wrote:
{noformat}*hi everybody,
please send me a ajax with jsp application
suppose i enter a word in text area ajax will populate/suggest all string from database ,who started
from that entering character(s).like a google string search.
please send full source code
*{noformat}how about you do it yourself? -
Help Required -- Can we use SQL Query to READ data from SAP MDM Tables
Hi All,
Please help.........
Can we use SQL Query to READ(No Creation/Updation/Deletion just Read) Data from SAP MDM tables directly, without using MDM Syndicator.
Or direct SQL access to SAP MDM tables is not possible. Only through MDM Syndicator can we export data.
Thanks in Advance
RegardsAll the tables you create in Repository comes under A2i_CM_Tables in Database named as your repository name. So the tables names are fields of table A2i_CM_Tables. Now i tried it but cant make it.
Now, I dont think its possible to extract all fields in tables and there values using select query. May be pure sql guy can do that or not.
But there is no relation of data extraction and syndicator. Data is viewed in Data Manager. and you can also store data in a file from DM also.
BR,
Alok -
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 required in writing the query
I have the following level accounts
10000
11000
11100
11101
11200
11201
12000
12100
12101
12102
12103
20000
21000
21100
21101
22000
22101
21200
21201
I have to take the amount of the child account and sum it to the parent account as below:
11100 = 11101 + 11102 - 11103+.........
11000 = 11100 + 11200 + 11300+.........
10000 = 11000 + 12000 + 13000+.........
21100 = 21101 + 21102 - 21103+.........
21000 = 21100 + 21200 + 21300+.........
20000 = 21000 + 22000 + 23000+.........
Please help...
Thanks in advance.SQL> with t as (
2 select 10000 ACCOUNT, NULL BEG_BAL, NULL END_BAL from dual union all
3 select 11000,NULL,NULL from dual union all
4 select 11100,NULL,NULL from dual union all
5 select 11101,1750.00,4150.00 from dual union all
6 select 11102,1550.00,3150.00 from dual union all
7 select 11103,1650.00,3200.00 from dual union all
8 select 11200,NULL,NULL from dual union all
9 select 11201,800.00,1250.00 from dual union all
10 select 11202,1550.00,3150.00 from dual union all
11 select 12000,NULL,NULL from dual union all
12 select 12100,NULL,NULL from dual union all
13 select 12101,1200.00,5000.00 from dual union all
14 select 12102,1500.00,3000.00 from dual union all
15 select 12103,1550.00,2750.00 from dual union all
16 select 20000,NULL,NULL from dual union all
17 select 21000,NULL,NULL from dual union all
18 select 21100,NULL,NULL from dual union all
19 select 21101,2000.00,6500.00 from dual union all
20 select 21102,1500.00,3500.00 from dual union all
21 select 21103,1750.00,3550.00 from dual union all
22 select 22000,NULL,NULL from dual union all
23 select 22100,NULL,NULL from dual union all
24 select 22101,1550.00,3550.00 from dual union all
25 select 22102,2550.00,5550.00 from dual union all
26 select 21200,NULL,NULL from dual union all
27 select 21201,2550.00,6500.00 from dual union all
28 select 21202,3550.00,7500.00 from dual
29 )
30 select account,
31 beg_bal,
32 end_bal,
33 sum(beg_bal) over(order by account range between current row and grouping_window follow
ing) group_beg_bal,
34 sum(end_bal) over(order by account range between current row and grouping_window follow
ing) group_end_bal
35 from (
36 select t.*,
37 case
38 when account / 10000 = trunc(account / 10000) then 9999
39 when account / 1000 = trunc(account / 1000) then 999
40 when account / 100 = trunc(account / 100) then 99
41 when account / 10 = trunc(account / 10) then 9
42 else 0
43 end grouping_window
44 from t
45 )
46 order by account
47 /
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
10000 11550 25650
11000 7300 14900
11100 4950 10500
11101 1750 4150 1750 4150
11102 1550 3150 1550 3150
11103 1650 3200 1650 3200
11200 2350 4400
11201 800 1250 800 1250
11202 1550 3150 1550 3150
12000 4250 10750
12100 4250 10750
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
12101 1200 5000 1200 5000
12102 1500 3000 1500 3000
12103 1550 2750 1550 2750
20000 15450 36650
21000 11350 27550
21100 5250 13550
21101 2000 6500 2000 6500
21102 1500 3500 1500 3500
21103 1750 3550 1750 3550
21200 6100 14000
21201 2550 6500 2550 6500
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
21202 3550 7500 3550 7500
22000 4100 9100
22100 4100 9100
22101 1550 3550 1550 3550
22102 2550 5550 2550 5550
27 rows selected.
SQL> SY. -
Hi All,
We have a query which is taking hell lot of time in production due to Full Table Scan on the table AP_ACCOUNTING_EVENTS.
We have then tried to force the index AP_ACCOUNTING_EVENTS_N1 on the query by applying hints.
Now the table is doing a range scan using index AP_ACCOUNTING_EVENTS_N1.
But to my surprise, the query with hints is taking even more time than that of query without hint.
Database: 10.0.2
and Application : 11.5.10.2
PFB the query:
SELECT api.invoice_id,
SUBSTR(pov.segment1, 1, 5) supplier_code,
DECODE(pov.segment1,
'A',
SUBSTR(api.attribute7, 1, 20),
SUBSTR(pov.vendor_name, 1, 20)) supplier_name,
MIN(TRUNC(aae.creation_date)) approval_date
FROM po_vendors pov, ap_invoices api, ap_accounting_events aae
WHERE api.payment_status_flag = 'Y'
AND api.source not in ('A', 'B', 'C')
AND aae.source_table = 'AP_INVOICES'
AND aae.creation_date >= sysdate - 2
AND aae.creation_Date < sysdate
AND aae.accounting_event_id = aae.ACCOUNTING_EVENT_ID
AND pov.vendor_id = api.vendor_id
AND aae.source_id = api.invoice_id
GROUP BY api.invoice_id,
SUBSTR(pov.segment1, 1, 5),
DECODE(pov.segment1,
'A',
SUBSTR(api.attribute7, 1, 20),
SUBSTR(pov.vendor_name, 1, 20))
Kindly Help.
Thanks,Tuning request
Take a look at the
When your query takes too long ...
HOW TO: Post a SQL statement tuning request - template posting -
Help required in writing PCR's
Hi All,
Update on this is highly appreciable and points will be rewarded.
Thanks & Regards,
surya
Hi All,
To calculate OT as per the Client requirement two PCR's needs to be wriiten.
1. OT should not be paid if it is less than 30 mins.
2. OT should be calculated as follows:
(basic2/26/8no. of hours).
Your help in this regard is highly appreciable.
Thanks & Regards,
Surya
Edited by: Surya Prakash Kanuru on Sep 15, 2008 9:55 AMHi,
No need to write to 2 PCR ,with one pcr itself it can be calculated . Here maintain overtime hrs in 15 infotype ,such that overtime hrs will be stored in a wage type say 9ovt .
Pcr can be build in this way
90vt
num = 90vt(where overtime hrs will be transfered to num)
num?0.5
< ( if the hrs is 30 mins )
your logic
= (30 mins )
logic calc
> (30 min)
amt = 1001 (basic wage type)
amt = 1001 div 2
some calc
div ana (for dividing with the no of hrs and passing the overtime value to the amt)
addwt *
Hope it helps u
Regards,
Prince Elvis -
Hi SDNers,
I have a requirement to write UDF, can anybody help me in acheiving the code.
Requirement:-
If I am getting 5 as my input to UDF, I need to generate five 001's to my output of UDF.
I tried to loop the input and used result.addValue("001"); but not working.
Please help in getting java logic for this udf.
Thanks
Jayaram.GHi Luis,
Thanks for your quick response.
I am using context in my udf.
My code is like this.
for(int i=0;i<var1.length;i++)
result.addValue("001");
As I am getting 5 as input and I am using Var1.length, the udf is generating only one 001. But I need five 001.
Regards,
Jayaram.G -
Help required in writing a query
hi
Consider a table (ShogenValue) with following data:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 40001 B0001 2
4329 1 50300 B0001 3
4329 1 40001 C0001 4
4329 1 50300 C0001 5
4329 1 60001 C0001 6
Select
si_val
From
ShogenValue
Where
model_id = 4329
And
header_id = 1
And
serial_no = '60001'
Is it possible to write a modified version of above query which will bring the following result:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 50300 B0001 3
4329 1 60001 C0001 6
Meaning if a record exists for a particular shogen_no (Shogen_no C0001 has value corrosponding to '60001' in above query), pick it up, if it
does not exist (Shogen_no B0001 does not have value corrosponding to '60001' in above case) then pick a record with one level less serial number ('50300' in above case) and so on.
Thanx
Regards
Omer ImtiazThis should help, although it will probably not perform. Try it and see what the plan for it is.
SELECT
FROM
shogenvalue sv,
(SELECT
max(serial_no) serial_no_max,
shogen_no
FROM
shogenvalue
WHERE
model_id = 4329
AND header_id = 1
AND serial_no <= '60001'
GROUP BY
shogen_no
) svm
WHERE
sv.serial_no = svm.serial_no_max
AND sv.shogen_no = svm.shogen_no
;HTH,
Lennert -
Help Required in writing a small program
Create ajava program to manage vehicles.the class vehicle must have five attributes
maybe he cant figure out what five attributes a
vehicle class can have :-)boolean hasSpinnningRims;boolean isPimped;int noOf Wheels;
public final int LEFT_IN_MANCHESTER = 0;
public final int LEFT_IN_BRADFORD= 1;
public final int DELL_BOY = 3; -
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.
ThanksFew 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. -
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 -
Help needed in building a sql query
Hello,
I am using Oracle 10g db.
I have 3 tables table1 and table2 and table3
I am writing one sql query which is like
select table1.a a1,(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
from table1
Now the b1 value may give more then 1 values so when i am trying to execute the query its giving me error.
What i would like to have is if it gives returns more then 1 value then add that value as a new column means if b1 gives like abc and def as values.
Then i want the sql to return like
acolvalue abc def as a single row.
Is this possible to do?
ThanksHello,
The approach which i took is i wrote a function which gives me the b values , sseparated.
Then i am building a outer query considering the max of b so i just found there are max 10 values which one row is showing.
select b11,b12,b13,,,b10
from (
select table1.a a1,func(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
from table1)
but now i am facing problem like the value of b1 is a,b,c
i want to use the substr and instr function to get
a as b11
b as b12
c as b13
can anyone pls help me out to write a query? i am getting b11 but other values are somehow not coming.
for b11
i used
substr(b1,1,instr(b1,',',1,1)-1)
Thanks
Maybe you are looking for
-
I had some old Word documents on a Dell laptop that I wanted to view on my iMac. Using a USB drive, I successfully transferred the files from the Dell to the iMac. Some of the documents open up normally for viewing, etc. Others do not. A Pages bo
-
How to install driver for Intel HD on Satellite C660-22V?
Hi I could not reply below so here is my question. http://forums.computers.toshiba-europe.com/forums//thread.jspa?threadID=68240 As*** I do not know if you work for toshiba but what else am I suppose to do if the driver installed on a new laptop does
-
However, i had about a gigabyte (or so) free before I added only ten more songs to my library. Now, though, when I try to sync, I get the following message: The iPhone "John Masella's iPhone" cannot be synced because there is not enough free space to
-
Looking for suggestions on this workflow...any better way to do it? I shoot and edit primarily in HDV, with a little added footage from a Canon 60D, resulting in two different video formats. I don't want to mix them in one timeline, requiring frequen
-
Each time I walk over to the iMac with the iTunes library on it, it seems to be syncing the show that I am watching on AppleTV with 2.0. The shows are DVDs (The West Wing Series 6, not that it probably matters) ripped with Handbrake. The episode I'm