Need sql for this logic
Hi,
Below is my table with columns like a,b,c
a b c
1 null null
null 2 null
null null 3
I need output like a b c
1 2 3
Hi,
Here's one way
SELECT MIN (a) AS a
, MIN (b) AS b
, MIN (c) AS c
FROM my_table;
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), 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
Similar Messages
-
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. -
Hi,
I need sequence for autogenerate of code
Table 1
id code
We need to autogenerate code for every new entity of id
ex:
id code
sbi sbi001
hsb hsb002
xyz xyz003
And
ex:
id code
sbi s001
hsb h002
xyz x003You can use a Sequence and Trigger in combination like this
create table t
id varchar2(10)
, code varchar2(25)
create sequence t_seq;
create or replace trigger t_trig before insert on t for each row
declare
l_seq integer;
begin
select t_seq.nextval into l_seq from dual;
:new.code := :new.id || to_char(l_seq, 'fm099');
end;
insert into t (id) values ('sbi');
insert into t (id) values ('hsb');
insert into t (id) values ('xyz');
select * from t; -
Need SQL for this simple logic..
Hi,
I have a select statement
select msi.segment1,micv.CATEGORY_SET_NAME from
MTL_system_ITEMs msi, MTL_ITEM_CATEGORIES_V micv where msi.INVENTORY_ITEM_ID = micv.INVENTORY_ITEM_ID
and msi.ORGANIZATION_ID = 853 and msi.ORGANIZATION_ID = micv.ORGANIZATION_ID and
msi.segment1 = 'C0005'
which gives me output
segment1 CATEGORY_SET_NAME
C0005 Country Of Origin
C0005 HS COMMODITY
C0005 Inventory
C0005 MFG PLANT
C0005 Order Management Categories
C0005 Purchasing Categories
C0005 Sales and Marketing
I have another select statement
which gives me output
segment1 CATEGORY_SET_NAME
C2601ZE Inventory
C2601ZE Sales and Marketing
C2601ZE Purchasing Categories
C2601ZE Order Management Categories
C2601ZE MFG PLANT
Where there are 2 rows missing for part C2601ZE from 2nd select
I want output like below for 2 missed rows which are from 2nd select
segment1 CATEGORY_SET_NAME
C2601ZE Country Of Origin
C2601ZE HS COMMODITY
MINUS is working but its working only for segment1 not for set_name
Thanks in Advance
Devenderselect msi.segment1,micv.CATEGORY_SET_NAME
from MTL_system_ITEMs msi, MTL_ITEM_CATEGORIES_V micv
where msi.INVENTORY_ITEM_ID = micv.INVENTORY_ITEM_ID
and msi.ORGANIZATION_ID = 853
and msi.ORGANIZATION_ID = micv.ORGANIZATION_ID
and msi.segment1 = 'C2601ZE'
and micv.CATEGORY_SET_NAME not in (
select micv.CATEGORY_SET_NAME
from MTL_system_ITEMs msi, MTL_ITEM_CATEGORIES_V micv
where msi.INVENTORY_ITEM_ID = micv.INVENTORY_ITEM_ID
and msi.ORGANIZATION_ID = 853
and msi.ORGANIZATION_ID = micv.ORGANIZATION_ID
and msi.segment1 = 'C0005');
(Not Tested) -
Hi Gurus
I have below situtation which need to be sorted out by SQL (10g version)
Below is the sample data.
Date Amt1 Amt2 Amt3 Totl
201009 10 10 10 30
201010 20 20 20 90
201011 30 20 10 150
Totl is the calculation field and remaining data is available in DB table say tab1. If you see logic of identifying Totl --> addition of Amt1,Amt2,Amt3 with Totl of prev month. For 201010 it is 20+20+20 =60 and this 60 will need to added to 201009 totl 30 and hence final sum is 90.
Please provide to resolve this.You need to do cumulative sum.
with t
as
select 201009 dt, 10 a1, 10 a2, 10 a3 from dual union all
select 201010, 20, 20, 20 from dual union all
select 201011, 30, 20, 10 from dual
select dt, a1, a2, a3, sum(a1+a2+a3) over(order by dt) tot
from t -
How to construct a SQL for this logic.
Hi,
I have a requirement like, i need to derive a column with a calculation.
Here is the psedocode,
count of occurance (deptno=10)/count (deptno=10)
Desired result:
If the deptno =10 occurs 3 times in the table then at the fist time the calcuation should be,
1/3, second time 2/3, third time 3/3 and so on.
How can i construct this in a sql query. Please help.
Any help will be appreciated with points.
Thanks.WITH DATA AS
(SELECT DEPTNO,
ROW_NUMBER() OVER(PARTITION BY DEPTNO ORDER BY DEPTNO) RN,
COUNT(DEPTNO) OVER(PARTITION BY DEPTNO ORDER BY DEPTNO) CNTDEPTNO
FROM SCOTT.EMP)
SELECT DEPTNO, RN, CNTDEPTNO, TO_CHAR(RN)||'/'||TO_CHAR(CNTDEPTNO) AS CNT
, RN/CNTDEPTNO AS calcl
FROM DATAyou want this?
Edited by: Mahir M. Quluzade on Mar 10, 2011 10:59 AM -
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 -
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. -
Internal Error - Unable to generate SQL for this Scheduled Workbook
I am encountering the following error when loading the results of a Scheduled Workbook;
Internal Error - Unable to generate SQL for this Scheduled Workbook (If you scheduled this workbook using a previous version of Discoverer, please reschedule and re-open)
This only happens for one of the scheduled workbooks and I am struggling to find an explanation to the problem. There are no reference to database links in the workbook so I can rule that out as a cause.
Does anyone have any suggestions to what might be causing the problem?
Many thanks
StewartHi,
The version is OracleBI Discoverer Plus Version 10.1.2.48.18. Do you think this has anything to do with it?If you are on this version, then you have the recommended patches applied.
Did you try to reschedule the workbook and see if this helps in resolving the issue?
I would suggest you enable server logging as this may help in collecting more details about the error.
Note: 403689.1 - How To Generate Discoverer 10g (10.1.2) Session Server Logs In Text Format
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=403689.1
Regards,
Hussein -
pls i need help for this simple problem of my palm os zire 72. pls share your ideas with me.... i tried to connect my palm os zire72 in my desktop computer using my usb cable but i can't see it in my computer.. my palm has no problem and it works well. the only problem is that, my desktop computer can't find my palm when i tried to connect it using usb cable. is thier any certain driver or installer needed for it so that i can view my files in my palm using the computer. where i can download its driver? is there somebody can help me for this problem? just email me pls at [email protected] i really accept any suggestions for this problem. thanks for your help...
If you are using Windows Vista go to All Programs/Palm and click on the folder and select Hot Sync Manager and then try to sync with the USB cable. If you are using the Windows XP go to Start/Programs/Palm/Hot Sync Manager and then try to sync. If you don’t have the palm folder at all on your PC you have to install it. Here is the link http://kb.palm.com/wps/portal/kb/common/article/33219_en.html that version 4.2.1 will be working for your device Zire 72.
-
Please provide code for this logic
Hi,
table
id code
145623 xyz001
178956 sbh002
165895 sbi003
As per this logic,for every new entity of id a new autogenerated code will be generated.
This (xyz or sbh or sbi) code should be fetched using select query (select b_code into table.code from cmp where c_id =145623)
using id(145623). And 001,002 is autogenerated code and should be concentrated with xyz ex: xyz001
Here we can use trigger with sequence
Could you please help me..How many times you will ask same question???
You need to use pl/sql block for your requirement some thing like this:
create sequence and add into pl/sql block like:
>>Select max(count) into temp_var where id=’sbi’
>>New_code:=’sbi’+temp_var;
Now you need to optimize it...
Thanks... -
How to write code for this logic, plz help me very urgent
Hi All,
i am new to sap-abap, i got this work and i m working on this can any body help me in writing code, plz help me, this is very very urgent.
here i m giving my logic, can anybody send me the code related to this logic.
this is very urgent .
this program o/p should be in ALV format and need to create one commond 'SAVE" on this o/t list if user clicks save processedon and processedby fields in ZFIBUE should be updated automatically.
i am creating one custom table zfibue having fields: (serialno, bukrs, matnr,prdha,hkont,gsber,wrbtr,budat, credate, cretime,processed, processedon, processedby,mapped)
fields of zfibue:
serailno = numc
bukrs = char
matnr = char
prdha = char
hkont = char
gsber = char
wrbtr = char
budat = date
credate = date
cretime = time
processed= char
processedon = date
processedby = char
mapped = char are belongs to above type data types
and seelct-optionfields: s_bukrs for bseg-bukrs
s_hkont for bseg-hkont,
s_budat for bkpf-budat,
s_processed for zfibue-processed,
s_processedon for zfibue-processedon,
s_mapped. for zfibue-mapped
parameters: p_chk1 as checkbox,
p_chk2 as checkbox.
p_filepath type rlgrap-filename.
1.1 Validate the user inputs (S_BUKRS and S_HKONT) against respective check tables (T001 and SKB1). If the validation fails, provide respective error message. Eg: Invalid input for Company Code.
1.2 Fetch SERIALNO, BUKRS, MATNR, PRDHA, HKONT, GSBER, WRBTR, BUDAT, CREDATE, CRETIME, PROCESSED, PROCESSEDON, PROCESSEDBY, MAPPED from table ZFIBUE into internal table GT_ZFIBUE where BUKRS IN S_BUKRS, HKONT IN S_HKONT, BUDAT IN S_BUDAT, PROCESSED IN S_PROCESSED, PROCESSEDON IN S_PROCESSEDON, and MAPPED IN S_MAPPED.
1.3 If P_CHK2 = X, go to step 1.11. Else continue.
1.4 If P_CHK1 = X, continue. Else go to step 1.9
1.5 Fetch MATNR, PRDHA from MARA into GT_MARA for all entries in GT_ZFIBUE where MATNR = GT_ZFIBUE-MATNR.
1.6 Sort and delete adjacent duplicates from GT_MARA based on MATNR.
1.7 Loop through GT_ZFIBUE where PRDHA = blank.
Read Table GT_MARA based on MATNR = GT_ZFIBUE-MATNR.
IF sy-subrc = 0.
Move GT_MARA-PRDHA to GT_ZFIBUE-PRDHA.
Modify Table GT_ZFIBUE. Update Product Hierarchy
Endif.
Fetch PRDHA, GSBER from ZFIBU into GT_ZFIBU for all entries in GT_ZFIBUE where PRDHA = GT_ZFIBUE-PRDHA.
Read Table GT_ZFIBU based on PRDHA = GT_ZFIBUE-PRDHA.
IF sy-subrc = 0.
Move GT_ZFIBU-GSBER to GT_ZFIBUE-GSBER.
Move X to GT_ZFIBUE-MAPPED.
Modify Table GT_ZFIBUE.
Endif.
Endloop.
1.8 Modify database table ZFIBUE from GT_ZFIBUE.
1.9 Fill the field catalog table GT_FIELDCAT using the details of output fields listed in section Inputs/Outputs (above).
Eg: LWA_ FIELDCAT -SELTEXT_L = 'Serial Number.
LWA_ FIELDCAT -DATATYPE = NUMC.
LWA_ FIELDCAT -OUTPUTLEN = 9.
LWA_ FIELDCAT -TABNAME = 'GT_ZFIBUE'.
LWA_ FIELDCAT-FIELDNAME = 'SERIALNO'.
Append LWA_FIELDCAT to GT_FIELDCAT
Note: a) The output field GT_ZFIBUE-PROCESSED will be editable marking INPUT = X in field catalog (GT_FIELDCAT).
b) The standard ALV functionality will be used to give the user option for selecting all or blocks of entries at a time.
c) The PF-STATUS STANDARD_FULLSCREEN from function group SLVC_FULLSCREEN will be copied to the program and modified to include a SAVE button.
1.10 Call the function module REUSE_ALV_GRID_DISPLAY passing output table GT_ZFIBUE and field catalog GT_FIELDCAT. Additional parameters like I_CALLBACK_PF_STATUS_SET (= ZFIBUESTAT) and I_CALLBACK_USER_COMMAND (=HANDLE_USER_ACTION) will also be passed to handle user events. Go to 2.14.
1.11 Download the file to P_FILEPATH using function module GUI_DOWNLOAD passing GT_ZFIBUE.
1.12 Exit Program.
Logic to be implemented in routine Handle_User_Action
This routine will have the following interface:
FORM Handle_User_Action USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
ENDFORM.
Following logic will be implemented in this routine:
1. If r_ucomm = SAVE, continue. Else exit.
2. Loop through GT_ZFIBUE where SEL_ROW = X. Row is selected
a. IF GT_ZFIBUE-PROCESSED = X.
i. GT_ZFIBUE-PROCESSEDON = SY-DATUM.
ii. GT_ZFIBUE-PROCESSEDBY = SY-UNAME.
iii. MODIFY ZFIBUE FROM work area GT_ZFIBUE.
Endif.
Endloop.Hi Swathi,
If it's very very urgent then you better get on with it, don't waste time on the web. Chop chop. -
What is a efficient SQL for this query ?
Hi,
I am using 9.2 database. Suppose I am having following 2 tables
Table p having only one column i.e. 'a'. Values in this column are
a1
b1
c1
d1
Table Q having three columns a, b, c
a1, 1, 100
a1, 2, 50
b1, 1, 30
b1, 2, 40
d1, 2, 90
Table Q can be joined only using column a.
Table Q can have multiple or no records for column a in table p. Based on above sample data, I want following output
a1, 100, 50
b1, 30, 40
c1
d1, 90
Kindly tell be how can I achive this in most efiicient way !!!
thanks & regards
PJPI only have you two tracks about how do it.
If you want all the columns from p with or wihout q you have to do:
11:35:58 SQL> l
1 select p.*, q.*
2 from p,q
3* where p.a = q.a (+)
11:37:27 SQL> /
For change the order of the colums for rows you can see the url, the are more examples like that only need to search "columns for rows" in this forums.
Anyway:
with rt as
select 'a1' a, 1 b, 100 c from dual union
select 'a1', 2, 50 from dual union
select 'b1', 1, 30 from dual union
select 'b1', 2, 40 from dual union
select 'd1', 2, 90 from dual)
--select * from rt
select a, decode('1','0','0',rtrim(xmlagg(xmlelement(b, b || ',')).extract('//text()'),',')) b
, decode('1','0','0',rtrim(xmlagg(xmlelement(c, c || ',')).extract('//text()'),','))
from rt
group by a
Message was edited by:
cth
Other way:
select a, ltrim(b,',') as b, ltrim(c,',') as c
from (
select row_number() over (partition by a order by length(b) desc) as rn, a, b,c
from (select a, sys_connect_by_path(b, ',') as b,
sys_connect_by_path(c, ',') as c
from (
select row_number() over (partition by a order by b) as rn, a, b,c
from rt) y
connect by rn = prior rn + 1 and prior a = a
start with rn = 1
where rn = 1
Message was edited by:
cth -
Need SQL for below scenerio .
Hi Experts,
Consider an Order Table with the following table structure with some Sample Data:
ORDER_DAY
ORDER_ID
PRODUCT_ID
QUANTITY
PRICE
01-JUL-11
O1
P1
5
5
01-JUL-11
O2
P2
2
10
01-JUL-11
O3
P3
10
25
01-JUL-11
O4
P1
20
5
02-JUL-11
O5
P3
5
25
02-JUL-11
O6
P4
6
20
02-JUL-11
O7
P1
2
5
02-JUL-11
O8
P5
1
50
02-JUL-11
O9
P6
2
50
02-JUL-11
O10
P2
4
10
Need SQL to get all products that got sold both the days and the number of times the product is sold.
Desired output :
PRODUCT_ID
COUNT
P1
3
P2
2
P3
2
Thanks and Regards,
Sumanth KulkarniHi,
SumanthKulkarni wrote:
Hi
I tried below approach , but i didnt get desired output for P1
select count(s) a,product_id from
(select count(product_id) s,order_day ,product_id from orders group by order_day,product_id
order by product_id asc) t
group by product_id
having count(s) >1
Thanks and Regards
Sumanth Kulkarni
Run the sub-query by itself, and look at the results. You should see something like this:
S ORDER_DAY PRODUCT_ID
2 01-JUN-2011 P1
1 02-JUN-2011 P1
1 01-JUN-2011 P2
When you're computing the column a for the final output, do you want to count how many rows of this result set have product_id='P1'? That's what COUNT does, but I don't think that's what you want.
Do you want to add up the numbers in the S column? Then use SUM (s), not COUNT (s).
You could also do the whole job without a sub-query, like this:
SELECT COUNT (*) AS a
, product_id
FROM orders
GROUP BY product_id
HAVING COUNT (DISTINCT order_day) > 1 -
Need Sql for terda data database
Can any one help send me the sql for teradata database. for creating the variables. I need to create variables for Last month begin date and last month end date.
I am trying this tera data Sql this is for curent month date.
select cast(current_date as date) - (extract (day from cast(current_date as date)) - 1) + interval '1' month - 1
I need tera data sql for Last month begin date and last month end date. I searched various forums but could not get the answer. Any suggesstions please.
Maybe you are looking for
-
How do you make a button download pdf file in edge animate?
Hi does anyone know the code or know how to make a download button in edge animate, that when you click the button it will fetch a pdf file from your pc root folder and offer it to download.
-
HT1420 how can i deotherize a computer that i have reinstalled the os for
i upgraded my laptop to windows 8 and need to sync my itunes to my iphone 4s but i need to altherize this laptop and deotherize the old version with windows 7 please deotherize all my devices and i can sort out the rest
-
When I edit photos in iPhoto it deletes them
Hi, I'm having an issue with iPhoto '09: when I edit my photos it deletes them. It doesn't seem to happen if I adjust the temperature or tint, but if I manipulate any elements between (and including) exposure and de-noise it deletes my photo. The wei
-
View State question - changing states and custom states
Hi all, I'm working on an application that lets a user register for an event. Each event has associated child information: conferences, tickets, etc. associated with it. What I'm trying to do is create some sort of checkbox list so that, when a user
-
Realtime data integration with Third party application
A customer wants to send data to a third party application when a user modifies some information on a business object (ie PO Amount, Employee Name etc). How can you trap this change as close to realtime as possible within SAP?