Need a query for this logic
Hi
table1
id cus_id val
boi p gh
hdc s vc
123 p xy
123 s xz
123 m xb
123 ll zx
Note: 123 is default values
o/p
id cus_id val
boi p gh
boi s xz
boi m xb
boi ll zx
hdc s vc
hdc p xy
hdc m xb
hdc ll zx
123 p xy
123 s xz
123 m xb
123 ll zx
Hi,
Pleaes check this:
WITH t AS
(SELECT 'boi' id, 'p' cus_id, 'gh' val FROM DUAL
UNION ALL
SELECT 'hdc', 's', 'vc' FROM DUAL
UNION ALL
SELECT '123', 'p', 'xy' FROM DUAL
UNION ALL
SELECT '123', 's', 'xz' FROM DUAL
UNION ALL
SELECT '123', 'm', 'xb' FROM DUAL
UNION ALL
SELECT '123', 'll', 'zx' FROM DUAL),
tt AS
(SELECT *
FROM t
WHERE id = '123')
SELECT a.id, b.cus_id, b.val
FROM t a, tt b
WHERE a.id <> '123' AND a.cus_id <> b.cus_id
UNION ALL
SELECT * FROM t
order by 1;
Cheers,
Manik.
Similar Messages
-
Need SQL code for this logic - - From Serial and To serial no.
In Forms 4.5 Screen I have two text boxes where i will be entering From Serial No
and to serial no.
I want the code which will check whether any number in between these from and to serial exists in a table or not ?
For Example
Select * from t; -- contains
serial number
321-456-789
123-456-654
321-569-986
321-569-987
When I enter from Serial no 321-456-789 and to serial no as 321-456-789.. I should get a message sayinig that 321-456-789 exists.
When I enter from Serial no 321-569-986 and to serial no as 321-569-988.
I should get a message sayinig that 321-456-986 exists.
I should get a message sayinig that 321-456-987 exists.
I should get a message sayinig that 321-456-988 not exists.
is it possible with a SQL query or do we need to go for procedure or temp table ?
If anybody ahving similar code please post it here.
Thanks in Advance
DevenderHi Devender,
Try this :
SQL> select * from t;
SN
321-456-789
123-456-654
321-569-986
321-569-987
SQL> var sn1 varchar2(11)
SQL> exec :sn1 := '321-569-986'
Procédure PL/SQL terminée avec succès.
SQL> var sn2 varchar2(11)
SQL> exec :sn2 := '321-569-988'
Procédure PL/SQL terminée avec succès.
SQL>1 select a.sn, decode(t.sn,null,'does not exists','already exists')
2 from
3 (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
4 ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
5 ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
6 from (select level
7 from dual
8 connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
9 )
10 )a,
11 t
12* where a.sn=t.sn(+)
SQL> /
SN DECODE(T.SN,NUL
321-569-986 already exists
321-569-987 already exists
321-569-988 does not exists
SQL> exec :sn1 := '321-456-789'
Procédure PL/SQL terminée avec succès.
SQL> exec :sn2 := '321-456-789'
Procédure PL/SQL terminée avec succès.
SQL> l
1 select a.sn, decode(t.sn,null,'does not exists','already exists')
2 from
3 (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
4 ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
5 ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
6 from (select level
7 from dual
8 connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
9 )
10 )a,
11 t
12* where a.sn=t.sn(+)
SQL> /
SN DECODE(T.SN,NUL
321-456-789 already exists
SQL> Nicolas. -
Need sql querry for this logic
Hi,
Edited by: 937506 on Jun 10, 2012 7:35 AM937506 wrote:
Hi,
I have table like this,based on this table data i need one column for example "Value" based on this condition,
KEY A_VAL ETA_VAL RANGE DATE_ID SITE AREA UNIT Monthnumber Year
1111 35 36 50.45 2778 PLANT1 AREA2 CDU-4 8 2011
1111 40 41 50.45 2783 PLANT1 AREA2 CDU-4 8 2011
9010 114 37 50.45 2779 PLANT1 AREA2 CDU-3 8 2011
9010 41 35 50.45 2784 PLANT1 AREA2 CDU-3 8 2011
9011 1500 38 50.45 2789 PLANT2 AREA3 DHT-1 8 2011
9012 43 37 50.45 2774 PLANT1 AREA1 DHT-2 8 2011
9012 38 39 50.45 2781 PLANT1 AREA1 DHT-2 8 2011
9013 39 40 50.45 2782 PLANT1 AREA2 FCC 8 2011How to ask question
SQL and PL/SQL FAQ -
Need query for this logic..
Hi,
Need a SQL query to achieve this..
Ex:
Select object_name from user_objects where object_name in('EMP','DEPT')
You will get 2 table names.
DEPT
EMP
Now I want to count how many records are there in each table
Output should be like
DEPT 4
EMP 13
Please let me know how can we write it ?
Thanks in Advance
DevenderYou need to create a function to cout rows.
Here is an example
CREATE OR REPLACE
FUNCTION get_rows (
t_owner IN varchar2 default user,
t_name IN varchar2
RETURN integer
IS
outVal integer;
BEGIN
select null
into outVal
from dba_tables
where ( owner=t_owner )
and ( table_name=t_name );
execute immediate 'select count(*) from '||t_owner||'.'||t_name into outVal;
RETURN outVal;
EXCEPTION
WHEN no_data_found THEN
return null;
END;
/And here is the query.
Processing ...
select owner,object_name,get_rows(owner,object_name) n_rows
from dba_objects
where object_name in('EMP','DEPT')
Query finished, retrieving results...
OWNER OBJECT_NAME ROWS
SCOTT EMP 14
SCOTT DEPT 4
2 row(s) retrieved -
Need SQL statement for this logic....
Hi,
I want a SQL statement for updating the following changed last number .
Cuurently its:
SELECT * FROM TEST;
LAST NUMBER CHANGED LAST NUMBER
123518
12355265
123674659
9087648970
After updating with the required SQL statement table should look like
LAST NUMBER CHANGED LAST NUMBER
123518 0000123518
12355265 0012355265
123674659 0123674659
9087648970 9087648970
the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
Appreciate your help.
Thanks in advance
Devenderselect last_number, lpad(to_char(last_number), 10 , '0') FROM test
-
9. DATA SET (ALIAS TBL)
SSN Name Background Check Date Review Date
123456789 Bob Smith 4/15/04 5/10/05
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
REQUIREMENTS
Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
EXPECTED RESULTSET
SSN Name Background Check Date Review Date
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULLDATA SET (ALIAS TBL)
------------------------------------------------------------------------------------------------------------------|
SSN Name Background Check Date Review Date|
-------------------------------------------------------------------------------------------------------------------|
123456789 Bob Smith 4/15/04 5/10/05
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
REQUIREMENTS
Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
EXPECTED RESULTSET
SSN Name Background CheckDate Review Date
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL -
Hi
I need a procedure 4 this logic,
Need to get 32+ inputs in procedure of same type varchar2,
If comp_id !=360
insert 32 inputs in table column-> value using custom-id
Note:
Column : brand-code,value,custom_name using custom_id
brand-code gets from comp-id from another table
i/p- from procedure comp_id and 32 inputs
This 32 inputs should use varray cocept
end if;
ex:
table 1
brand_code custom-id value editble
table 2
custom-id custom-name
Could you please share ur suggestionsCreate or replace procedure cdm_cl_proc is
v_sqnum number(3);
cursor c1 is
select dcn, pp_code from d_cl_ext;
Cursor c2 is
Select t_code, s_date, area_chrg, rc_pct from d_c_p_ext;
Begin
for v1 in c1
Loop
update d_cl set pp_code = v1.pp_code
where dcn=v1.dcn;
select d_sqnum into v_sqnum from d_cl
where dcn=v1.dcn;
For v2 in c2
Loop
Update d_c_p set area_chrg= v2.area_chrg, rc_pct=v2.rc_pct
Where t_code= v2.t_code and s_date = v2.s_date
and d_sqnum = v_sqnum;
if mod(c2%rowcount,1000)=0 then
commit;
end if;
End loop;
if mod(c1%rowcount,1000)=0 then
commit;
end if;
End loop;
Commit;
End;
I amable to load the data when dcn is matched but, if the dcn is not matched no data found error is coming. can u suggest error handling for this. -
consider this situation,
Two or more productid will be accquired by same customerid, by same shipvia, on the same day of the week of shipped date. i want the simple query for this.
my tables are from northwind:
[orders] = OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry.
[orders details] = OrderID, ProductID, UnitPrice, Quantity, Discount.
i tried some but it is not exact, it gives wrong result.
select pd.CustomerID,pd.ProductID, pd.no_of_time_purchased, sd.ShipVia, sd.same_ship_count, shipped_day from
select ProductID,o.CustomerID,COUNT(productid) as no_of_time_purchased
from orders o join [Order Details] od on o.OrderID=od.OrderID group by ProductID,o.CustomerID
having count(od.ProductID) >1) pd
join
(select OrderID,customerid, shipvia, count(shipvia)as same_ship_count, DATENAME(DW,ShippedDate)as shipped_day from orders
group by customerid, ShipVia, ShippedDate having COUNT(ShipVia) > 1 ) sd
on sd.CustomerID=pd.CustomerIDHi,
I think I have a solution that will at least give you a clue how to go about it. I have simplified the tables you mentioned and created them as temporary tables on my side, with some fake data to test with. I have incldued the generation of these temporary
tables for your review.
In my example I have included:
1. A customer which has purchased the same product on the same day, using the same ship 3 times,
2. Another example the same as the first but the third purchase was on a different day
3. Another example the same as the first but the third purchase was a different product
4. Another example the same as the first but the third purchase was using a different "ShipVia".
You should be able to see that by grouping on all of the columns that you wich to return, you should not need to perform any subselects.
Please let me know if I have missed any requirements.
Hope this helps:
CREATE TABLE #ORDERS
OrderID INT,
CustomerID INT,
OrderDate DATETIME,
ShipVia VARCHAR(5)
CREATE TABLE #ORDERS_DETAILS
OrderID INT,
ProductID INT,
INSERT INTO #ORDERS
VALUES
(1, 1, GETDATE(), 'ABC'),
(2, 1, GETDATE(), 'ABC'),
(3, 1, GETDATE(), 'ABC'),
(4, 2, GETDATE() - 4, 'DEF'),
(5, 2, GETDATE() - 4, 'DEF'),
(6, 2, GETDATE() - 5, 'DEF'),
(7, 3, GETDATE() - 10, 'GHI'),
(8, 3, GETDATE() - 10, 'GHI'),
(9, 3, GETDATE() - 10, 'GHI'),
(10, 4, GETDATE() - 10, 'JKL'),
(11, 4, GETDATE() - 10, 'JKL'),
(12, 4, GETDATE() - 10, 'MNO')
INSERT INTO #ORDERS_DETAILS
VALUES
(1, 1),
(2, 1),
(3, 1),
(4, 2),
(5, 2),
(6, 2),
(7, 3),
(8, 3),
(9, 4),
(10, 5),
(11, 5),
(12, 5)
SELECT * FROM #ORDERS
SELECT * FROM #ORDERS_DETAILS
SELECT
O.CustomerID,
OD.ProductID,
O.ShipVia,
COUNT(O.ShipVia),
DATENAME(DW, O.OrderDate) AS [Shipped Day]
FROM #ORDERS O
JOIN #ORDERS_DETAILS OD ON O.orderID = OD.OrderID
GROUP BY OD.ProductID, O.CustomerID, O.ShipVia, DATENAME(DW, O.OrderDate) HAVING COUNT(OD.ProductID) > 1
DROP TABLE #ORDERS
DROP TABLE #ORDERS_DETAILS -
How to form a query for this requirment
Hi Friends,
I have a database table in which I store the employee data along with his phone number. Now this row of data can repeat for different phone number depending on if it is office phone or home phone or cell phone.
But in the output of query, I need name of empoyee and other three columns namely "Home Phone", "Office Phone" and "Cell Phone".
If employee has three rows for each kind of phone, then in the result of query all three columns for phone numbers should be filled, otherwise as many columns should be filled with data as different phone numbers employee has.
Can any one please post SQL query for this scenario ?
Thanks in AdavanceI cannot imagine, that second and third query are
under any circumstances faster as first one, but i
can imagine that they are slower You stated that query without the inline view can only be faster. Did you check on optimizer plans or use tkprof to verify your claim?
A quick check on those two selects
SELECT object_id, object_type, object_name
FROM user_objects;
SELECT object_id, object_type, object_name
FROM (SELECT object_id, object_type, object_name
FROM user_objects)
;didn't show any changes in the explain plan unter 10g1.
C. -
Need a query for monthly Report
Hello All,
I need a query for monthly report,
comp_code
emp_id
dept_id
work_day
100
A100
MECH
01/01/2013
100
A100
MECH
02/01/2013
100
A100
MECH
03/01/2013
100
A100
MECH
04/01/2013
100
A100
MECH
05/02/2013
100
A100
MECH
08/02/2013
100
A100
MECH
09/02/2013
100
A100
MECH
10/02/2013
100
A100
MECH
12/05/2013
100
A100
MECH
13/05/2013
100
A101
CIV
01/04/2013
100
A101
CIV
02/04/2013
100
A101
CIV
03/04/2013
100
A101
CIV
04/04/2013
100
A101
CIV
06/04/2013
100
A101
CIV
06/06/2013
100
A101
CIV
07/06/2013
100
A101
CIV
08/06/2013
100
A101
CIV
09/06/2013
100
A101
CIV
10/06/2013
100
A101
CIV
11/12/2013
100
A101
CIV
12/12/2013
100
A101
CIV
13/12/2013
100
A101
CIV
14/12/2013
Dear friends this the sample table of my report.In which table has contain list of employees with their working days(actual table has contain almost 5laks of records).
suppose user choose the date between 01/01/2013 and 31/12/2013 then the result should be like this.
comp_code
emp_id
dept_id
month
Total_work
100
A100
MECH
JANUARY
4
100
A100
MECH
FEBRUARY
2
100
A100
MECH
MARCH
0
100
A100
MECH
APRIL
0
100
A100
MECH
MAY
2
100
A100
MECH
JUNE
0
100
A100
MECH
JULY
0
100
A100
MECH
AUGUST
0
100
A100
MECH
SEPTEMBER
0
100
A100
MECH
OCTOBER
0
100
A100
MECH
NOVEMBER
0
100
A100
MECH
DECEMBER
0
100
A101
CIV
JANUARY
0
100
A101
CIV
FEBRUARY
0
100
A101
CIV
MARCH
0
100
A101
CIV
APRIL
5
100
A101
CIV
MAY
0
100
A101
CIV
JUNE
5
100
A101
CIV
JULY
0
100
A101
CIV
AUGUST
0
100
A101
CIV
SEPTEMBER
0
100
A101
CIV
OCTOBER
0
100
A101
CIV
NOVEMBER
0
100
A101
CIV
DECEMBER
4Hi,
If you want the output to include months where no work was done (with 0 in the total_work column) then you need to outer-join a "table" that has one row per month, and make it a partitioned outer join:
WITH got_end_points AS
SELECT TRUNC (MIN (work_day), 'MONTH') AS first_month
, TRUNC (MAX (work_day), 'MONTH') AS last_month
FROM table_x
, all_months AS
SELECT ADD_MONTHS (first_month, LEVEL - 1) AS a_month
, ADD_MONTHS (first_month, LEVEL) AS next_month
FROM got_end_points
CONNECT BY LEVEL <= 1 + MONTHS_BETWEEN (last_month, first_month)
SELECT t.comp_code
, t.emp_id
, t.dept_id
, m.a_month
, COUNT (t.work_day) AS total_work
FROM all_months m
LEFT OUTER JOIN table_x t PARTITION BY (t.comp_code, t.emp_id, t.ept_id)
ON t.work_day >= a.a_month
AND t.work_day < a.next_month
GROUP BY t.comp_code
, t.emp_id
, t.dept_id
, m.a_month
ORDER BY t.comp_code
, t.emp_id
, t.dept_id
, m.a_month
As posted, this include every month that is actually in the table. You can change the first sub-query if you want to enter first and last months.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Point out where the query above is giving the wrong results, and explain, using specific examples, how you get the correct results from the given data in those places. If you changed the query at all, post your code.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
I want sql query for this output
hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.Will this help:
SQL> with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21 and (rn = 1 or ACCOUTID is null)
22 /
ID AID T
2 1 B
4 2 D
8 G
7 F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21* and rn = 1
SQL> /
ID AID T
2 1 B
4 2 D
8 G
--which follows the description you've given, but not the output -
Help needed in query for Materialized View
Hi,
I want to create a materialized view which has some precalcultaed values.
I have four dimension tables out of which one is a Time Dimension table with levels as Year->Quarter->Month.
The precalculations are the moving averages and cummulative values of Sales Amt on the dimension values over a period of 4 Months.
The dimension tables are Clients, Products, Channel, Time.
Fact Table is Sales_Fact which will have the sales amount for different members of the dimension.
Since my fact table is very huge, i want to create a materialized view where i could store the required calculated measures, here Moving Average of Sales Amt for each Client, Product, Channel dimensions over a period of 4 Months.
Can anybody help with writing the query for this..Any help in this regard will be appreciated..
Please give me suggestions for this..Check this link.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1612
Regards
Raj -
Require a Message mapping for this Logic.
Hi Experts,
I require a Message mapping for this Logic.
In the Source there are 4 fields and, the Target side, the fields should appear like this.
Source Structure- File
Record
|-> Header
Order_No
Date
|-> Item
Mat_No
Quantity
Target Structure-IDoc
IDoc
|-> Header
|-> Segment
Delivery_Order_No
Recv_Date
|-> Item
|-> Segment
Delivery_Order_No
Material_Num
Recv_Quantity.
The Logic is for every Order number an IDOC is generated.And if the Material num matches then the quantity should be added. and important note is that the material numbers are different for every order number. That means if a material number is 2 in the order number A. Then the material number can never be 2 in any of the order numbers.Here is the following with an example for the above scenario.
For example:-
we have
Source Structure- File
Order-no Date Mat_No Quantity
1 01/02/2011 A 10
1 01/02/2011 B 15
1 01/02/2011 A 10
2 01/02/2011 C 10
2 01/02/2011 C 10
3 01/02/2011 D 20
3 01/02/2011 D 10
3 01/02/2011 E 25
Target Structure-IDoc
Delivery_Order_No Recv_Date Material_Num Recv_Quantity
1 01/02/2011 A 20
1 01/02/2011 B 15
2 01/02/2011 C 20
3 01/02/2011 D 30
3 01/02/2011 E 25
So for this example total of 5-Idocs created. That means for this example if Order_No is 1 When the Mat_No is A the quantity gets added. For this Scenario 1 IDoc with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) is generated by adding the quantity field in the Target Side. Similarly if Order_No is 1 when the Mat_No is B then separate IDoc is generated with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) in the Target Side. Similarly, if Order_No is 2 when the Mat_No is C, an IDoc is generated with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) by adding the quantity field in the Target Side. ike wise the process goes on upto 3.Kindly do the needy..
Thanq very much in advance..
Edited by: Prashanth Bharadwaj on Oct 17, 2011 1:29 PMHi Prashanth,
Concatinate the two fields OrderNo and MaterialNo and follow the below logic which will resolve your problem.
concatinationOfOrderNo&MaterialNo>removecontext>sort>splitByValueChange>collapseContext-->IDOC
concatinationOfOrderNo&MaterialNo>removecontext>sort>splitByValueChange>collapseContext>splitByEachValue>subString(0,1)-->Delivery_Order_No
formatByExample>collapseContext>SplitByEachValue-->Recv_Date
FormatByExample:
input1:resulrOfSortByKey
input2:concatination>removecontext>sort-->SplitByValuChange
sortByKey:
input1:concatination-->removecontext
input2:date-->removecontext
concatinationOfOrderNo&MaterialNo>removecontext>sort>splitByValueChange>collapseContext>splitByEachValue>subString(1,1)-->Material_Num
formatByExample>sum>Recv_Quantity
FormatByExample:
input1:sortByKey
input2:concatination>removecontext>sort-->SplitByValueChange
SortByKey:
input1:concatination-->removecontext
input2:Quantity-->removeContext
Regards,
Priyanka. -
Need a query for export table data .....
Hi,
I need a query for exporting the data in a table to a file.
Can anyone help me ?
Thanking You
JeneeshSQL> spool dept.txt
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> spool off
SQL> ed dept.txt -
Need sql query for typical scenario
Hello Champs,
I have a scenario where I am suppose to fetch data from a schema which is developed by other team ... (there are no primary keys even)
the table structure is -
Column A Column B Column C Column D
1 h 6 u
1 h 7 u
1 h 8 u
2 g 9 i
2 g 0 i
2 g 7 i
3 t 3 h
3 t 4 h
3 t 5 i
and my output should be exactly like :
1 h 6,7,8 u
2 g 9,0,7 i
3 t 3,4 h
so basically I want comma separated values for column c where remaining column values are same ...
is it possible to achieve this result via SQL?? if not then what is the other solution??
Please help .. I am working in IST and need solution urgently for this .. please help .
TIA,
Regards,
Chintanif you have 11g
WITH t AS (SELECT 1 cola,
'h' colb,
6 colc,
'u' cold
FROM DUAL
UNION
SELECT 1,
'h',
7,
'u'
FROM DUAL
UNION
SELECT 1,
'h',
8,
'u'
FROM DUAL
UNION
SELECT 2,
'g',
9,
'i'
FROM DUAL
UNION
SELECT 2,
'g',
0,
'i'
FROM DUAL
UNION
SELECT 2,
'g',
7,
'i'
FROM DUAL
UNION
SELECT 3,
't',
3,
'h'
FROM DUAL
UNION
SELECT 3,
't',
4,
'h'
FROM DUAL
UNION
SELECT 3,
't',
5,
'i'
FROM DUAL)
SELECT cola, colb, listagg (colc, ',') WITHIN GROUP (ORDER BY colc) colc, cold
FROM t
GROUP BY cola, colb, cold
COLA COLB COLC COLD
1 h 6,7,8 u
2 g 0,7,9 i
3 t 3,4 h
3 t 5 i
Maybe you are looking for
-
Error while Creating a formula for field AZNOR (T-Code : OP17)
Dear Experts, i am facing a problem in Transaction OP17 while creating a formula for field AZNOR ( No of indivual capacity in work center) in work center (T-Code : CR02) . It shows the error The data object "F" has no component called "AZNOR''.. Plea
-
Excise & sales tax legal requirements
Dear Experts, After creating Excise Invoice, what are the activities SD consultant has to carry out regarding excise registers and sales tax registers and what are the legal requirements to be filled up from SD point of view. Kindly guide me on the s
-
I recently bought a MacBook Pro and migrated to it from my iMac using my Time Machine backup with Apple's Migration Assistant. However, I notice every time I open Mail, the Mail Upgrade window is displayed. Can anyone enlightened me to way this is? M
-
Marketing Online Customization Problem
Hi, Currently I am working on Oracle Marketing Online Customization. I want to develop a applet, and add it in the Marketing Online home page. How to make my Applet a web bin and customer can select whether to show it or not. Many thanks.
-
Hello. I have recently discovered that I have far more songs in my file system than I actually have in itunes itself. This poses two questions I was hoping someone could help me out with: 1. Is there a way to determine which files are in Itunes, and