How to convert multiple lines in a row in oracle?
There is outputstatus st_nm County
AN OPEN 12
A NARROW 13
B OPEN 1
B CLOSE 2
EXPECTED RESULTS
st_nm OPEN_count CLOSE_COUNT
A 12 13
1 2 B
give the possibility of solutions?
Published by: 886380 on September 30, 2011 05:53
Published by: 886380 on September 30, 2011 05:54
Published by: 886380 on September 30, 2011 05:56
Hello
This is called a Pivot .
Here's a way to do it:
SELECT st_nm
, MIN (CASE WHEN status = 'OPEN' THEN cnt END) AS open_count -- COUNT by itself is not a good column name
, MIN (CASE WHEN status = 'CLOSE' THEN cnt END) AS close_count
FROM existed
GROUP BY st_nm;
The best way depends on your exact requirtements and your version of Oracle. (The query above will work in Oracle 8.1 and higher).
For more information, see the FAQ for the forum page:
SQL and PL/SQL FAQ
Tags: Database
Similar Questions
-
How to convert multiple lines in 1 row of columns across
Hello
My DB 10g
My data as below,
I've already tilt it by84A8E46E9366 20111008133638 84A8E46E9366 20111112000531 84A8E46E9366 20111212004432 84A8E46E9366 20120127173533 84A8E46E9366 20120226235444
and get the result as below with only 2 columnselect msid, rtrim (xmlagg (xmlelement (e, fee || '|')).extract ('//text()'), '|') fee from aaa_bill where msid='84A8E46E9366' and fee is not null group by msid;
but I need the result to be on multiple columns.84A8E46E9366 20111008133638|20111112000531|20111212004432|20120226235444|20120127173533
so I tried the following
but the result, only the first stringselect msid,REGEXP_SUBSTR ( fee , '^[^|]*' ) from ( select msid, rtrim (xmlagg (xmlelement (e, fee || '|')).extract ('//text()'), '|') fee from aaa_bill where msid='84A8E46E9366' and fee is not null group by msid ) ;
84A8E46E9366 20111008133638
is it possible to get Thos on several columns each string on column separated automatically because I have about 20000 msid separateHello
See the FAQ forum: {message identifier: = 9360005}
In Oracle 10, you can do this:
WITH got_c_num AS ( SELECT msid , fee , ROW_NUMBER () OVER ( PARTITION BY msid ORDER BY fee -- or whatever ) AS r_num FROM aaa_bill WHERE ... ) SELECT msid , MIN (CASE WHEN c_num = 1 THEN fee END) AS col_1 , MIN (CASE WHEN c_num = 2 THEN fee END) AS col_2 , MIN (CASE WHEN c_num = 3 THEN fee END) AS col_3 ... , MIN (CASE WHEN c_num = n THEN fee END) AS col_n FROM got_c_num GROUP BY msid ORDER BY msid -- If wanted ;
Note that you must specify the number of columns in the output. If you are unsure, do a high hypothesis. The query works always; unused columns will be NULL.
Published by: Frank Kulash on 12 March 2012 14:45
-
Convert multiple lines in a row
Hello
DB version: 10.2.0.3
It's the entry
NAME Total Free ITEM1 150 50 ITEM2 200 175 Expected result:
Please tell how to get the result in format (SQL using case or nested case) below
(XXX_utilized columns is on Total - free)
ITEM1_TOTAL ITEM1_Utilized ITEM1_Free ITEM2_TOTAL ITEM2_Utilized ITEM2_Free 150 100 50 200 25 175 Kind regards
Veera
with
the entry like
("ITEM1" select name, 150 total, 100 50 used, free of all the double union)
Select 'ITEM2', 200, 25, 175 double
)
SELECT max (case name when total ' ITEM1' then end) item1_total,.
Max (case name when 'ITEM1' then used end) item1_utilized,.
Max (case name when free ' ITEM1' then end) item1_free,.
Max (case name when total ' ITEM2' then end) item2_total,.
Max (case name when 'ITEM2' then used end) item2_utilized,.
Max (case name when free ' ITEM2' then end) item2_free
Since the entry
ITEM1_TOTAL ITEM1_UTILIZED ITEM1_FREE ITEM2_TOTAL ITEM2_UTILIZED ITEM2_FREE 150 100 50 200 25 175 Concerning
Etbin
-
merge multiple lines in a row (but multiple columns)
How to merge multiple lines in a row (but several columns) effectively.
For example
IDVal IDDesc Id_Information_Type Attribute_2 Attribute_3 Attribute_4 Attribute_5 Attribute_1 IdNum
23 asdc 1 location USA NM ABQ four seasons 87106
23 asdc 1 Stats 2300 91.7 8.2 85432
23 asdc 1 Audit 1996 June 17 1200
AAFC 65 2 location USA TX AUS Hilton 92305
65 AAC 2 Stats 5510 42.7 46 9999
AAFC 65 2 Audit 1996 July 172 1100
where different attributes mean different for each Information_type.
For example, for Information_Type = location
Attribute_1: countries
Attribute_2: State and so on.
For example, for Information_Type = Stats
Attribute_1 designates the Population
Attribute_2: percentage of ethnicity American and so on.
I want to create a view that shows as below:
IDVal IDDesc IDNum country state city hotel ZipCode American Population % other % area Audit year Audit AuditMonth Type AuditTime
23 asdc 1 USA NM ABQ reviews 87106 2300 91.7 46 85432 1996 June 17 1200
AAFC 65 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
Thank youHello
This is called pivoting . The FAQ forum has a section on this subject: {message identifier: = 9360005}
I hope that answers your question.
If not, post your best attempt, as well as some examples of data (CREATE TABLE and INSERT, only relevant columns instructions) and also publish outcomes from these data. (See you the desired results, but they are very difficult to read because they are not formatted. Use \.tags, as described in the forum FAQ, below.) Explain, using specific examples, how you get the results you want from the data given. Always say which version of Oracle you're using (e.g., 11.2.0.2.0). This is always important, but especially so with pivots. See the forum FAQ {message:id=9360002}
-
How to add multiple lines when the button is clicked
How to add multiple lines when the click on button now is just add a row .plz give me idea how... waiting for answer
/ public final class screen extends MyScreen
{
/**
* Creates a new object of MyScreen
*/
ObjectChoiceField obj1 obj2, obj3, obj4.
Table of String() = {'101 ', ' 102'};
String of shadow [] = {"Shade1", "Shade2"};
Rolls of string [] = {'101 ', ' 102'};
String cutting [] = {"100-150", "150-200"};
Chain of selectedindex1, selectedindex2, selectedindex3, selectedindex4;
LabelField lbl1 lbl2, lbl3, lbl4;
GFM LinedGridFieldManager;
HFM HorizontalFieldManager, hfm1, hfm2 hfm3;
VerticalFieldManager vfmMain;
public MyScreen()
{
Set the displayed title of the screen
hfm1 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
hfm2 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
hfm3 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
HFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_RIGHT);
vfmMain = new VerticalFieldManager (Manager.NO_VERTICAL_SCROLL |) Manager.NO_HORIZONTAL_SCROLLBAR);
obj1 = new ObjectChoiceField ("", graph, 0, FIELD_LEFT);
obj2 = new ObjectChoiceField ("", blind, 0, FIELD_LEFT);
Obj3 = new ObjectChoiceField ("", rolls, 0, FIELD_LEFT);
Obj4 = new ObjectChoiceField ("", cuts, 0, FIELD_LEFT);
LBL1 = new LabelField("");
LBL2 = new LabelField("");
lbl3 = new LabelField("");
lbl4 = new LabelField("");
ButtonField btnAdd = new ButtonField ("ADD", FIELD_RIGHT);
GFM = new LinedGridFieldManager (4, LinedGridFieldManager.VERTICAL_SCROLL);
hfm1.setMargin (20, 0, 10, 0);
hfm1. Add (new LabelField ("Chart"));
hfm1. Add (obj1);
hfm1. Add (new LabelField ("Shade"));
hfm1. Add (obj2);
hfm2. Add (new LabelField ("Rolls"));
hfm2. Add (Obj3);
hfm2. Add (new LabelField ("Cuts"));
hfm2. Add (Obj4);
HFM. Add (btnAdd);
GFM. Add (new LabelField ("Chart"));
GFM. Add (new LabelField ("Shade"));
GFM. Add (new LabelField ("Rolls"));
GFM. Add (new LabelField ("Cuts"));
vfmMain.add (hfm1);
vfmMain.add (hfm2);
vfmMain.add (hfm3);
vfmMain.add (hfm);
vfmMain.add (new SeparatorField());
vfmMain.add (gfm);
Add (vfmMain);
btnAdd.setChangeListener (new FieldChangeListener()
{
' Public Sub fieldChanged (field field, int context) {}
TODO self-generating method stub
selectedindex1 = chart [obj1.getSelectedIndex ()];
selectedindex2 = shade [obj2.getSelectedIndex ()];
selectedindex3 = rolls [obj3.getSelectedIndex ()];
selectedindex4 = cuts [obj4.getSelectedIndex ()];
While (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
{
LBL1. SetText (selectedindex1);
LBL2. SetText (selectedindex2);
lbl3. SetText (selectedindex3);
lbl4. SetText (selectedindex4);
GFM. Add (LBL1);
GFM. Add (LBL2);
GFM. Add (lbl3);
GFM. Add (lbl4);
}
}
});
}
}Hi Piya,
I run your code, and according to your logic that it works correctly.
It's adding that line only once because according to your logic that one line can be added to MDT, if you do not want to add line on each click on the button, follow these steps:
selectedindex1 = chart [obj1.getSelectedIndex ()];
selectedindex2 = shade [obj2.getSelectedIndex ()];
selectedindex3 = rolls [obj3.getSelectedIndex ()];
selectedindex4 = cuts [obj4.getSelectedIndex ()];Lbl1 LabelField = new LabelField("");
Lbl2 LabelField = new LabelField("");
LabelField lbl3 = new LabelField("");
LabelField lbl4 = new LabelField("");
If (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
{
LBL1. SetText (selectedindex1);
LBL2. SetText (selectedindex2);
lbl3. SetText (selectedindex3);
lbl4. SetText (selectedindex4);
GFM. Add (LBL1);
GFM. Add (LBL2);
GFM. Add (lbl3);
GFM. Add (lbl4);
} -
How to insert multiple lines using a single query
Hi all
How to insert multiple lines using a single query to the emp table?
I have the number of rows to insert into table x. consumes a lot of time. I tried to insert several lines using a single query, but get errors. I know exactly the query to do this.
Thank you
SunilLike this?
SQL> create table test(id number , dt date); Table created. SQL> insert into test values(&a,&b); Enter value for a: 1 --- It asked me and I entered 1 Enter value for b: sysdate --- It asked me and I entered sysdate old 1: insert into test values(&a,&b) new 1: insert into test values(1,sysdate) 1 row created. SQL>
g.
-
Convert multiple lines in a single value separated by commas
Is is possible to convert multiple lines in a single value by concatenating the value of each line in OBIEE. I think that IO had seem a blog related to this by I'm not able to find him. Essentially, here's what I would do:
Number of customer location
101
101 NY
101 PA
102 TX
102 CA
This is to convert
101. HE, NY, PA
102 TX, CA
Can you get it someone please let me know if this is possible and how to operate it.
Thanks in advance for the help.You can do this by creating a DB function,
Visit this link
Re: Display of the horizontal valuesThank you
Vino -
How to convert my toolbar in 2 rows so that all my icons and apps to show?
How to convert my toolbar so that it appears on two lines?
Hello
1. which version of the Windows operating system is installed on your computer?
2. are you referring to the toolbar or the task bar?
3. If you are referring to the Internet Explorer toolbar, which version of Internet Explorer is installed on your computer?
If you are referring to the taskbar, then try the steps in the following Microsoft article and check if it helps.
Change appear on the taskbar buttons:
http://Windows.Microsoft.com/en-us/Windows7/change-how-buttons-appear-on-the-taskbar
The taskbar (overview):
For Windows 7: http://Windows.Microsoft.com/en-us/Windows7/the-taskbar-overview
For Windows Vista: http://windows.microsoft.com/en-US/windows-vista/The-taskbar-overview
For Windows Vista: http://windows.microsoft.com/en-US/windows-vista/Taskbar-recommended-links
And see also: Suggestions for a question on help forums:
http://support.Microsoft.com/kb/555375
Hope the information is useful, if you are referring to the Internet Explorer toolbar, then just reply to us for additional help.
-
I would like to be able to convert multiple photos of a subject in video high resolution using the timeline in PS CC.
Here's how you can import a folder of images which become images in a video layer.
Using Photoshop | Import video files and image sequences -
How to convert multiple DNG size full of lossy DNG in Lightroom?
Hello
When I select several DNG in Lightroom and my mac, go to menu > library > convert photo to DNG and then choose Convert to DNG with the lossy mode, only the selected DNG is converted. How to convert more at the same time? I have a large library, and I want to convert ~ 100 GB of photos at a loss.
Thanks in advance!
How to convert more at the same time? I have a large library, and I want to convert ~ 100 GB of photos at a loss.
Using Photos of the library/convert to DNG, if you're in something other than the display of the grid, one photo will be converted even if several are selected. Its the same way that all orders (perhaps not all) work in library mode, you must be in mode grid for multiple photo stock.
-
How to convert (multiple) output lines (multi-column)
HII
I have a weird request. But not sure how to get results out of it!
My query returns two rows to a query I asked.
Current result
10
20
Expected result
10 20
My problem here is that I wanted two values above to be stored in two variables in a single select statement.
If I use a cursor that my problem will be solved. But I'm not much interested in using a cursor for a simple select statement.
is there a possibility that I can convert the output of two lines to two columns?
I use Oracle Release 10.1.0.2.0
Windows Xp operating system.
People here will not appreciate the tags 'Urgent '. I know that :-(.
But some how I'm forced to use this tag "urgent." Sorry for that.
If no response, I will in another way can go to the slider :-(
Any help will be appreciated.
Thank you
Pavan
??? WITH the clause is just a quick way to produce one on the fly table with your sample data. I think you should do a lot of reading material. In any case, use:
select dept, max(decode(rn,1,location,null)) location_1, max(decode(rn,2,location,null)) location_2 from ( select dept, location, row_number() over(partition by dept order by location) rn from ( your-query ) ) group by dept /
SY.
-
How to insert multiple lines in viewobject with primary key?
Hello
I use Jdeveloper 11.1.1.3.0 version.
I create object entity based on the table of the database that have primary keys.
I created the view on this entity object. I created an array of viewobject, with CreatInsert button and my primary key in the table may while the new record is added.
Now my problem is that I have created several rows by pressing CreateInsert Button several rows of time are created and displayed in the table. I insert data in all columns of all rows when I click on the submit button (who have the Action "# {bindings.Commit.execute} ') will save data of any 1 line not all data line.
How can I save all the lines that is created in a single transaction?
Thanks in advance
AmitAmit,
I just tried this (all by default, no code written), and he recorded all of the lines. It must be something unique to your application. Michael asks a lot of questions.
John
-
How to convert the lines into columns dynamically
HII
I have a 'report_line' with the following data table
location_code line_code value
LOC1 L1 12
loc2 L1 13
LOC1 L2 15
loc2 L3 11
LOC3 L1 9
Now I want the o/p by converting the line_codes in clumns as below
L1 L2 L3
LOC1 12 15
13 11 loc2
LOC3 9
How can I do this dynamically. Line codes are not constatnt, they can change for each scenario.
Thank you
SandeepI want just a sql for this query and no. columns ' maximum of are 6.
In this case you can do.
--sample data with t as ( select 'loc1' location_code, 'L1' line_code, 12 value from dual union all select 'loc2', 'L1', 13 from dual union all select 'loc1', 'L2', 15 from dual union all select 'loc2', 'L3', 11 from dual union all select 'loc3', 'L1', 9 from dual ) --end of sample data select location_code, max(decode(line_code, 'L1', value, null)) L1, max(decode(line_code, 'L2', value, null)) L2, max(decode(line_code, 'L3', value, null)) L3, max(decode(line_code, 'L4', value, null)) L4, max(decode(line_code, 'L5', value, null)) L5, max(decode(line_code, 'L6', value, null)) L6 from t group by location_code
Here I used the WITH clause as an example of table. You can replace the "t" table name in the select statement with your actual table and remove the WITH clause.
-
How to capture multiple line String using regular expressions?
Hello
I have a simple program like this:
What I want to accomplish is to capture everything between > start and > to end with a single regular expression matching node. It seems that the definition of multiples? true or False does not help.
I'm using LabVIEW 2012.
If it is impossible to capture using a single node, that's fine. But I want to assure you that I can make full use of this node without combining several others.
Thank you!
> start([\w\s]*) > end
A point matches any character except line break characters. You have two of them.
-
How to convert multiple files in Illustrator CMYK?
A major challenge for the professional Illustrator. I have several illustrator files in RGB and need to convert them to CMYK because I need to use for printing. Are nearly 200 files. If it's images, it would be easy, because it will create an action in Photoshop and apply the batch processing function. But how to do something in Illustrator?
Perform the conversion on output in ID. There is no need to do it manually before hand. Check in the forum ID.
Maybe you are looking for
-
Equium A100: How connenct to WLan hotspot
I'm trying for the first time to use the laptop to connect to a wifi hotspot. Already working on broadband with success at home.Even if I can get up available suppliers and it says connected to chose an I can't do this 'leap' to IE, establish a conne
-
Are the current models for sale on Lenovo web site "WWAN Ready"? By that I mean that they include the housing of SIM card and antenna WWAN and are simply missing the WWAN modem card? I am interested to buy one now and then add the WWAN card later. Th
-
My new deskjet 1510 printer bought in Maryland, does not print with my HP Pavilion dv5218nr notebook. I tried for two days to get something to print. I was able to make a copy yesterday. Have down loaded on site and also the disc used to load the
-
I often get redirected to another site when I try to access the websites and he prays me click on elements of research. How can I fix?
-
How can I check to see if I have a bluetooth receiver installed on my system?
Problems of Bluetooth for a HP Media Center m8120n is installed with Vista Ultimate. I have a HP Media Center m8120n is installed with Vista Ultimate. I want to know if I have bluetooth already installed on this computer. It is Bluetooth when I typ