How to split the data based on one column
Dear All,
I have the table data like this.
type quantity revenue_mny count country
a 10 10 2 India
a 20 12 3 India
b 30 15 1 India
a 35 20 2 US
b 20 10 1 US
b 60 15 1 US
I woulkd like to split the date based on type column.
For each country, for Type "a" get the sum of revenue count quanity ans same for b
and all shuld come in on row for each country.
output should be like
country revenue_mny(For a) quantity(for a) count(For a) revenue_mny(for b) quantity(for b) count(For b)
India 22 30 5 15 30 1
US 20 35 2 25 80 2
I tried the below query . its not splittng the date for each country in one row.
select country,
sum(case when type='a') then revenue_mny else 0 end ) revenue_mny_a,
sum(case when type='b' then revenue_mny else 0 end ) revenue_mny_b
sum(case when type='a' then quantity else 0 end) quantity_a,
sum(case when type='b' then quantity else 0 end) quantity_b from
test
group by country
Please need your helo
Like this?
with t as
select 'a' type, 10 quantity, 10 revenue_mny, 2 cnt, 'India' country from dual union all
select 'a', 20, 12, 3, 'India' from dual union all
select 'b', 30, 15, 1, 'India' from dual union all
select 'a', 35, 20, 2, 'US' from dual union all
select 'b', 20, 10, 1, 'US' from dual union all
select 'b', 60, 15, 1, 'US' from dual
select country,
sum(case when type='a' then revenue_mny else 0 end ) revenue_mny_a,
sum(case when type='a' then quantity else 0 end) quantity_a,
sum(case when type='a' then cnt else 0 end) cnt_a,
sum(case when type='b' then revenue_mny else 0 end ) revenue_mny_b,
sum(case when type='b' then quantity else 0 end) quantity_b ,
sum(case when type='b' then cnt else 0 end) cnt_b
from t
group by country;result:
COUNTRY REVENUE_MNY_A QUANTITY_A CNT_A REVENUE_MNY_B QUANTITY_B CNT_B
India 22 30 5 15 30 1
US 20 35 2 25 80 2Or you can do it with a decode instead of case. The result will be the same:
with t as
select 'a' type, 10 quantity, 10 revenue_mny, 2 cnt, 'India' country from dual union all
select 'a', 20, 12, 3, 'India' from dual union all
select 'b', 30, 15, 1, 'India' from dual union all
select 'a', 35, 20, 2, 'US' from dual union all
select 'b', 20, 10, 1, 'US' from dual union all
select 'b', 60, 15, 1, 'US' from dual
select country,
sum(decode(type,'a',revenue_mny,0)) revenue_mny_a,
sum(decode(type,'a',quantity,0)) quantity_a,
sum(decode(type,'a',cnt,0)) cnt_a,
sum(decode(type,'b',revenue_mny,0)) revenue_mny_b,
sum(decode(type,'b',quantity,0)) quantity_b,
sum(decode(type,'b',cnt,0)) cnt_b
from t
group by country;(I changed tablename from TEST to T and columnname from COUNT to CNT, because you should not use reserved words as tablename or columnname.)
Edited by: hm on 09.10.2012 06:17
Similar Messages
-
How to split the IDOCS based on document number change whit out BPM
Hi all,
Thanks,for giving the responce..
Scenario:File to IDoc.
Problum1 : How to Split the IDocs based on document number change in the source file with out BPM.My file contains document numbers like
20000092
20000092
20000092
50000050
50000050
50000065
I want 3 IDocs in target system.i.e 1 for 20000092,20000092,20000092
2 for 50000050,50000050
3 for 5000006
By using external definations i am getting 6 IDOCs insted of 3.
Problum 2:Is there any chnges/modifications in Directory when we are using external definations.
Could u plz provide me the step by step process(Repository/Directory) with using of external definations.
Thanks in advance.
Regards,
KPHI,
for this no need of BPM.
You can think of Idoc bundling concept to acheive this-just you need to do the external definition to change the idoc occurence
/people/michal.krawczyk2/blog/2005/12/04/xi-idoc-bundling--the-trick-with-the-occurance-change
to achieve for each document no, one idoc, you can write small user defined function in the mapping with context handling you an achieve this.
For this e.g
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6bd6f69a-0701-0010-a88b-adbb6ee89b34
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/877c0d53-0801-0010-3bb0-e38d5ecd352c
Regards,
Moorthy -
When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators. Excel allows you to do this during the import.. Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.
Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
(I don't have an iPad, so I don't know the iOS answer.) -
How to Split the Date Column in OBIEE
Hi,
We have date column name :To_Date and format is MM/DD/YY HH:MM:SS .
How do split the date into YEARS,MONTH,DAY as new columns.
kindly help on this.
Regards.,
CHR
Edited by: 867932 on Nov 23, 2011 10:18 PMHi User,
All 3 functions can be written in rpd too.In BMM layer, duplicate the date column ->Goto Column Mapping tab-> Expression builder ->Select Functions-> Calendar Date/Time Functions-> Select DayofMOnth function. Your logical column's formula will look like,
DayofMonth(YourDateColumn)
Rgds,
Dpka -
How to transpose the data records (rows) to column(lists) using apd
Hi,
how to transpose the data records (rows) to column (lists) using apd in sap bw.
I do not want to use abap routine.only use the transpose rows to list transformation .
Pls provide the step by step procedure .
thanks,
NimaiSave youe file to transpose as a csv and in the header row of your file for the columns you want to transpose you need to put some soer of a tag before the column name (ie your colum header was for a period budget will be something lie 2011001:ZFIBDD)
1. You will need to create a new apd process (rsanwb)
2. Insert a "Read from Data File" data source object and map it file (,csv)
3. insert a transpose object into your apd process (middle row 4th one over in the transformations section)
4. under the definition tab in the transformation object select all the columns that are to be transposed into rows and move them to the transformed area, the grouping fields section should contain the rows that you want to now be columns
5.under the transformation tab enter in the seperator you selected under the Field Name/Infoobject area (ie. ZFIBDD)
6. under the details tab you need to enter in all the fields to be transformed and tner the transposition field (ie ZFIBDD)
7. Then you can insert a set of transformations and a DSO and link the newly transposed fields into that.
hope that helps -
How to find the Data Type of a column
Dear All,
How to find the Data Type of a Column dynamically in oracle Form.
Thanks and Regards,
Fazil
Edited by: user11334489 on Aug 25, 2012 9:06 PMhi,
you can use get_item_property built-in
eg:
declare
l_item VARCHAR2(10);
begin
l_item := Get_Item_Property('item_name',DATATYPE);
end; -
How to pick the data based on customer number
Hi All ,
greets....
i have a requirement to select the data based on customer number and then do furthur processing .
example:
this is some 10 dcouments in customer nr:v1000
and 20 documents in customer v2000 in a internal table how to select that,
thank s in advance.thier is an internal table which is having some 1000records.
and their is 6 customers.
in which i should pick the data based on customer number.
how to write a code for that? -
How to delete the data based on concurrent request Id
Hi
from account receivable to gl i am posted a cheque through concurrent program.
right now my problem is I want to delete that data in database tables based on concurrent request id.
how to delete that data based on concurent request id, Please give me some suggessionsWhat is the application version ? what exactly you want to achieve ?
Direct deletion is not recommended in oracle application database.
regards, -
Formating the Row Based on one column value
Hi Friends
I am trying to format the Entire row based on the value of the first column in my Answers.
Example if first column value in 'F' now i want the Entire row to be colored
I can do conditional formating on one column but i want to do it on the entire row
F 8.1 % 12.0 %
E 5.2 % 3.5 %
M 2.3 % 3.3 %
If any one has done this or any suggestions please respond
Thanks
SangIts a Pivot View
F 8.1 % 12.0 %
E 5.2 % 3.5 %
M 2.3 % 3.3 %
the column 1 --> F,E,M are the Product
the column 2 --> 8.1% , 5.2% , 2.3% are the sales in year 2008
the column 3 --> 12.0 % , 3.5 %, 3.3 % are the sales in year 2009
So will i be able to apply the formating in pivot view based on one column to other column If yes please let me know how or
suggest if this can be done using the BI Office , or BI publisher
sing the BI Office i can do the formating in Excel but once i refresh the data all the formating is gone ... :(
I am donno BI Publisher if we have to use BIP please suggest any solution its very very very urgent and important report formating they need here ....
Thanks in advance David
sango -
How to retrieve the data type of a column of a table?
Hi,
I want to retrieve the data type of a column of a table. At the moment I am querying "OCI_ATTR_DATA_TYPE" attribute but it is returning SQLT_CHR for both varchar2 and nvarchar2 data type columns. I need to distinguish between these two data types columns separately. Is there any API through which I could get the exact data type of a column i.e. "nvarchar2"?
Thanks in advance.
HashimHi,
This is the Oracle C++ Call Interface (OCCI) forum - I'm not sure if you are using OCCI or OCI (Oracle Call Interface - the C interface) since you reference "OCI_ATTR_DATA_TYPE" which is more of an OCI focus than OCCI.
In any case, you might take a look at "OCI_ATTR_CHARSET_FORM" which takes the following values:
#define SQLCS_IMPLICIT 1 /* for CHAR, VARCHAR2, CLOB w/o a specified set */
#define SQLCS_NCHAR 2 /* for NCHAR, NCHAR VARYING, NCLOB */So, if you have a datatype of SQLT_CHR and OCI_ATTR_CHARSET_FORM is SQLCS_IMPLICIT then you have a varchar2 if it is SQLCS_NCHAR then you have an nvarchar2.
If you are using OCCI and not OCI then take a look at MetaData::ATTR_DATA_TYPE and MetaData::ATTR_CHARSET_FORM which expose OCI_ATTR_DATA_TYPE and OCI_ATTR_CHARSET_FORM respectively.
Perhaps that will get you what you want.
Regards,
Mark -
How to get the data based on below data-----pls help me...
Hi,
i have the data in my table.......
SET_ID SET_Name Status date user_name
SET974 F698671 I 24/03/2011 10:40:05 TEST1
SET974 F698671 I 24/03/2011 10:40:05 TEST1
SET974 F698671 N 24/03/2011 10:40:05 TEST1
SET974 F698671 I 24/03/2011 10:40:05 TEST1
SET528 A258961 I 22/03/2011 9:40:05 TEST2
SET528 A258961 N 22/03/2011 9:40:05 TEST2
SET528 A258961 I 22/03/2011 9:40:05 TEST2
SET528 A258961 I 22/03/2011 9:40:05 TEST2
SET974 F698671 I 25/03/2011 13:40:05 TEST1
SET974 F698671 N 25/03/2011 13:40:05 TEST1
SET974 F698671 N 25/03/2011 13:40:05 TEST1
SET974 F698671 I 25/03/2011 13:40:05 TEST1
SET974 F698671 I 26/03/2011 15:40:05 TEST5
SET974 F698671 N 26/03/2011 15:40:05 TEST5
SET974 F698671 N 26/03/2011 15:40:05 TEST5
SET974 F698671 I 26/03/2011 15:40:05 TEST5
I want to know each user ,how many sets modified.
based on above input data,my output would be in the following way:
user_name no.of sets upated for single user
TEST1 2
TEST2 1
TEST5 1Based on your sample data, why does TEST1 have a count of 2? From what I can see, the only SET_ID that is associated with TEST1 is SET974 so I would think that you'd want TEST1 to have a count of 1.
If I ignore the data you posted and just look at the text of your requirements, I would guess that you wanted
SELECT user_name, COUNT( DISTINCT set_id ) cnt
FROM some_table
GROUP BY user_nameThis won't give the output you said you wanted based on the sample data you provided, however, for the reason I outlined above.
If you actually do expect to get the output you posted from the sample data you posted, can you explain in a bit more detail why TEST1 should have a value of 2? It would also be helpful to post the CREATE TABLE and INSERT statements rather than just dumping the data. If you provide DDL & DML, we can create the objects locally and verify our solutions rather than guessing based on eyeballing the data.
Justin -
How to fetch the data based on header in detail.
Hi,
Below is my requirement:
I need to create a two non-database control blocks(header and detail) with multirecord.
When i press the one button i need to fetch the data header block.
If i select the any record i need to get the detail record values in detail block.
Please suggest in which trigger i need to write the code. Please explain clearly.
Regards,
M. Satishhello
I agree with Mr. Andreas Weiden . use the standard function for the blocks.
First if you have any PK or FK relationship with the two tables then you can use the table wizard then just follow the procedure and be sure you click the checkbox which is default, automatically create relationship.
If you dont have PK/FK then just follow again the table block wizard ... just unclick the check box for autocreate relationship then press button to create base on the SQL join.
on the create join editor :
deptno = empdepno
the press okey. forms wizards will create all the rest... you can now notice a new object RELATIONSHIP below the DEPARMENT BLOCK and some forms genareted triggers.
And CHANGE THE BLOCK PROPERTIES TO UPDATE ABLE,INSERT ABLE, DELETE to NO.. IF YOU WANT ONLY ON DISPLAY
OR BETTER CREATE A 2 VIEWS CORRESPONDENT TO YOUR QUERY ON YOUR CURSOR.... and follow the procedure i gave above.
In your button:
go_block(your.block);execute_query(no_validate); -
Splitting the date based on the selection screen input
Hi all,
In the Selection screen of my report i had maintained two fields
SELECT-OPTIONS : S_DATE FOR TPCDATE-FROM_DATE.
PARAMETERS : P_NUMBER TYPE ZMMAREA-NUMBER.
I need to code such that
S_DATE should be splitted into P_NUMBER times
for example if P_NUMBER is 4 i need S_DATE should be splitted into 4 equal parts or near by equal parts
IF P_NUMBER is 2 i need S_DATE should be splitted into 2 equal parts or near by equal parts
Please suggest me the code of if any Function module exists fot this date splitting
Thanks in advance
Ajay.Dthough date question are not allowed, this requirement sounds little different.
you can take a difference between those days by: S_date-high - S_date-low.
then divide the difference by p_number. now you get the split positions.
now in a do enddo you can negate the dates by the split amount you got from the divisions.
like...
PARAMETERS: num type i.
select-OPTIONS: s_date for sy-datum.
data : gv_split type i, gv_temp type sy-datum.
gv_split = s_date-high - s_date-low.
gv_split = gv_split / num.
gv_temp = s_date-high.
do num times.
gv_temp = gv_temp - gv_split.
WRITE / gv_temp.
enddo. -
How to get the data type of a column?
I plan to construct a dynamic insert statement, so the column's type is needed, any possible to get what type of a column within mysql's table?
Message was edited by:
ioiioiThink about it this way
You can find out the type of the columns but can you convert the data items that you have to insert in to the table in to the proper column type. And you will also have to write a long if-else-if if you try to do this.
Just make the JDBC driver worry about this.
Try something like this.
public void insert(String table, Object data[]){
//You should write the getNumCollumns method
//to return the number of columns in the table
// Using Matadata Objects
int noOfColumns = getNumCollumns(table);
if (noOfColumns != data.length)
throw new IncorrectNumberOfValuesException();
//You should write this exception probably to be a subclass of SQLException
//Now construct the insert statement
StringBuffer sb = new StringBuffer("INSERT INTO ");
sb.append(table);
sb.append(" VALUES (");
for (int i=0; i<noOfColumns ; i++){
sb.append("?");
if (i< (noOfColumns-1))
sb.append(",");
sb.append(")");
//If you want you can cache the statement againt the table name
//Now create your prepared statement
PreparedStatement ps = connection.prepareStatement(sb.toString());
//Set the data
for (int i=0; i<data.length; i++){
ps.setObject(i+1, data);
//Execute
ps.executeUpdate();
ps.close();
In the above code the caller is responsible for sending the data with proper java type to be inserted and the driver will do the conversion. I have used this approach in a project few years ago and I havent got any complains.
WARNING: I havent compiled above code. It may have typos -
How to achieve grouping of data based on one column
Hello PL/SQL Gurus/experts,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
I have following table -
DROP TABLE T2;
create table T2(Manager,Employee) as select
'Nikki','Ram' from dual union all select
'Nina', 'Rita' from DUAL union all select
'Mike', 'Radha' from dual union all select
'Michael', 'Ratnam' from DUAL union all select
'Hendi', 'Ratna' from dual union all select
'Robert', 'Raman' from dual union all select
'Maria', 'Rolly' from dual union all select
'Kistrien', 'Rachna' from dual union all select
'Andrew', 'Ritvik' from dual union all select
'Emma', 'Ramesh' from dual union all select
'Andy', 'Ranpal' from dual union all select
'Brandy', 'Raunak' from dual union all select
'Nikki','Shyam' from dual union all select
'Nina', 'Sita' from DUAL union all select
'Mike', 'Sadhna' from dual union all select
'Michael', 'Satnam' from DUAL union all select
'Hendi', 'Satna' from dual union all select
'Robert', 'Samar' from dual union all select
'Maria', 'Sameer' from dual union all select
'Kistrien', 'Samrachna' from dual union all select
'Andrew', 'Satvik' from dual union all select
'Emma', 'Somesh' from dual union all select
'Andy', 'Sonpal' from dual union all select
'Brandy', 'Samar' from dual union all select
'Emma', 'Piyush' from dual union all select
'Andy', 'Pavan' from dual union all select
'Brandy', 'Paramjeet' from dual;Expected output -
Manager Employee
Nikki
Ram
Shyam
Nina Rita
Sita
Mike Radha
Sadhna
Michael Ratnam
Satnam
Hendi Ratna
Satna
Robert Raman
Samar
Maria Rolly
Sameer
Kistrien Rachna
Samrachna
Andrew Ritvik
Satvik
Emma Ramesh
Somesh
Piyush
Andy Ranpal
Sonpal
Pavan
Brandy Raunak
Samar
ParamjeetI thank to all of you in advance for your valuable time and inputsIn SQL, something like this...
SQL> ed
Wrote file afiedt.buf
1 select case when row_number() over (partition by emp.manager order by employee) = 1 then
2 mgr.manager
3 else
4 null
5 end as manager
6 ,emp.employee
7 from (select distinct manager from t2) mgr
8 join t2 emp on (mgr.manager = emp.manager)
9* order by mgr.manager, emp.employee
SQL> /
MANAGER EMPLOYEE
Andrew Ritvik
Satvik
Andy Pavan
Ranpal
Sonpal
Brandy Paramjeet
Raunak
Samar
Emma Piyush
Ramesh
Somesh
Hendi Ratna
Satna
Kistrien Rachna
Samrachna
Maria Rolly
Sameer
Michael Ratnam
Satnam
Mike Radha
Sadhna
Nikki Ram
Shyam
Nina Rita
Sita
Robert Raman
Samar
27 rows selected.If you want the managers on their own row with the employees underneath then you'll have to fudge it.
SQL> ed
Wrote file afiedt.buf
1 select case when row_number() over (partition by emp.manager order by employee nulls first) = 1 then
2 mgr.manager
3 else
4 null
5 end as manager
6 ,emp.employee
7 from (select distinct manager from t2) mgr
8 join
9 (select distinct manager, null as employee from t2
10 union all
11 select manager, employee from t2
12 ) emp on (mgr.manager = emp.manager)
13* order by mgr.manager, emp.employee nulls first
SQL> /
MANAGER EMPLOYEE
Andrew
Ritvik
Satvik
Andy
Pavan
Ranpal
Sonpal
Brandy
Paramjeet
Raunak
Samar
Emma
Piyush
Ramesh
Somesh
Hendi
Ratna
Satna
Kistrien
Rachna
Samrachna
Maria
Rolly
Sameer
Michael
Ratnam
Satnam
Mike
Radha
Sadhna
Nikki
Ram
Shyam
Nina
Rita
Sita
Robert
Raman
Samar
39 rows selected.
Maybe you are looking for
-
Why are percentages not shown in my chart?
I've made a table with data in percentage. However, when I make a column-chart, the data on the y-axis is shown in numbers (eg 0,31) instead of a percentage (31%). How can I change this? I tried to change this, but I can't edit when I go to 'axis' an
-
how does firefox know the details of my credit card to fill in a web form.? how can I prevent firefox from keeping a copy of my credit card numbers? == This happened == Not sure how often == i previously filled in the same web page a month ago.
-
My sisters computer is crapping out so they are trying to back everything up to move onto another computer. She can't seem to figure out where the pictures are located that she saved via BlackBerry Desktop Software. I have her HDD in an external case
-
Running VMWare and want Protection
A little help here for a Mac "newbie": I just downloaded XP (SP2) using VMware. Now I'm a bit concerned about protecting my laptop from all the "hazards" of hacking--which is why I made the switch in the first place. Can anyone recommend a good virus
-
I generated a document in a solaris machine which follows the encoding scheme "ISO-8859-1". This document contains symbols such as British currency pound symbols. Now, I am passing this document as an input to my application. My application runs on a