Merging multiple rows without using max group by
Hi guys,
Is there any better way to convert
with
test as
select '001' as id, 'Apple' as name, 'A' as segment1,null as segment2,null as segment3 from dual union all
select '001' as id, 'Apple' as name,null as segment1, 'P' as segment2,null as segment3 from dual union all
select '001' as id, 'Apple' as name,null as segment1,null as segment2, 'L' as segment3 from dual
select * from test
to
select '001' as id, 'Apple' as name, 'A' as segment1,'P' as segment2,'L' as segment3 from dual
without using max and group by?
There are about 5 million records and using max group by is slowing it down by a lot.
It is needed to be done by SQL.
Thank You
with
test as
select '001' as id, 'Apple' as name, 'A' as segment1,null as segment2,null as segment3 from dual union all
select '001' as id, 'Apple' as name,null as segment1, 'P' as segment2,null as segment3 from dual union all
select '001' as id, 'Apple' as name,null as segment1,null as segment2, 'L' as segment3 from dual
select distinct id, name
, last_value(segment1 ignore nulls) over (partition by id, name order by segment1) as seg1
, last_value(segment2 ignore nulls) over (partition by id, name order by segment2) as seg2
, last_value(segment3 ignore nulls) over (partition by id, name order by segment3) as seg3
from test
;No max or group by, but not necessarily any faster. If you post your actual query, some sample data with expected results, and the additional information requested in the following posts, then someone may be able to provide better suggestions.
When your query takes too long
When your query takes too long ...
How to Post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
Regards,
Bob
Similar Messages
-
Single step workflow with multiple approvers (without using a group)
Hi,
is it possible to have a single step workflow with multiple approvers without using a group? This is for a contract document.
i want to add a number of users based on particular logic. The approvers are random and do not belong to any particular group.
DO let me know if it is possible or if any of you have done that.
thanks in advance.
regards,
rubioHi Rubio,
I believe the behavior would be, if individual users are added as approvers then the system would require each approver to approve the document. However, if you use the user group, you could set the role so that it would be either ALL or ANY.
Regards,
Vikram -
How to manipulate data in multiple rows without using cursor??
Hi all,
I have a form in which there is a push button & 4 text fields.
Push button : Process
Text fields: Year, Month, Financial_To_Year, Financial_From_Date.
In database , there are tables like, CUSTOMER_MASTER, FD_ACCOUNT_MASTER, FD_ACCOUNT_DTL, CUSTOMER_YEARLY_INTEREST, etc.
In table FD_ACCOUNT_MASTER, there are columns, like CUST_CODE, FD_ACCT_NO, FD_AMOUNT, ACCT_OPEN_DT, ACCT_CLOSE_DATE, ACCT_TYPE, INTEREST_RATE, etc.
There are thousands of records in the table.
For Push button : Process , TRIGGER: When button pressed,
I have to do all the process of FD for all the FD_ACCOUNTS at once. Process means i have to calculate Interest for all the accounts, calculate interest monthly, quarterly, yearly and make the FD_Accounts disable after the date of ACCT_CLOSE_DATE is reached, make the accounts renewed , etc all the process.
But to do this process for multiple rows at once, we use cursor, but i don't want to use cursor as i feel its too tedious to do.
Is there any other way , where i do process of multiple records at once without using cursor??
Help me, Thank You.
Oracle Forms Builder 6i.
Oracle9i Enterprise Edition Release 9.2.0.1.0 - ProductionAn Update statement certainly can update sets of data instead single row updates:
UPDATE Statement
if you can't do it in a single statement you can use bulk processing as well:
PLSQL 101
cheers -
Merge multiple rows of same ID into Single row
Hi All,
I need the requirements of merging multiple rows of same ID as single row.
My Table Data:
ID Language1 Language2 Language3 Language4
1001 NULL JAPANESE NULL NULL
1001 SPANISH NULL NULL NULL
1001 NULL NULL NULL ENGLISH
1001 NULL NULL RUSSIAN NULL
Required Output Should be,
ID Language1 Language2 Language3 Language4
1001 SPANISH JAPANESE RUSSIAN ENGLISH
Please help me to achieve this output.
Tried grouping but its not working also producing the same result.
Thanks.
Live freee....Joy forever................ :)Try the below:
create Table Test_Sample(ID int,Language1 varchar(50), Language2 varchar(50), Language3 varchar(50), Language4 varchar(50))
Insert into Test_SAmple Values(1001,NULL,'JAPANESE', NULL, NULL),
(1001,'SPANISH', NULL, NULL, NULL),
(1001,NULL, NULL, NULL, 'ENGLISH'),
(1001,NULL, NULL, 'RUSSIAN', NULL)
Select ID,MAX(Language1),MAX(Language2),MAX(Language3),MAX(Language4)
From Test_Sample
Group by ID
Drop table Test_Sample -
Merging multiple rows in to a single row (when rows meet merging criteria)
Hi
I have a scenario to merge multiple rows in to a single rows when the data in those rows fall in merge criteria .Below is how my data is
Now the merging logic for the above rows is , we need to combine multiple rows in to a single row when the data in those rows permits us to do in that way. Simply saying , its like sandwich where we combine multiple things to a single piece.The output for
the above rows should be
Here we combined Row 1 ,2, 3 in to a single row as the data in those rows permits to merge in to single row. But the row 4 cannot be combined to any of those rows because the data in those rows doesn't permits us do a merge ( As the value of the column
JobSource for the row 4 is different from the other rows ) .
My original data has 56 columns , but for readability i kept only 9 columns.
can you please throw some idea on how to achieve this scenario. I know we need to use CTE for achieving this, but i am not able succeed in doing an iteration on multiple rows.
Appreciate your response .Thanks for your reply .
Rule for merging is simple . First of all there is no unique row identifier for each row , the fact table is not having an identity column in the database . I called row 1 , row 2 etc in my post above only to make better explanation of my scenario.
The rule for merge is below.
1) we can combine only when the data in a column for one row is null & the data in same column for the other row is not null . It should also satisfy the condition where the data in other columns should conflict each other.
2) Data for all columns for the merging rows should not be conflicting (i.e. we should not merge the rows when the data in a column is not equal to the same column in the other row
,considering not null value)
Steps in merging the above source data :
1) Consider the case of row 1 and row 2 in the source, we can combine these rows as the data is satisfying the rule 1 for columns (Jobsource,Flight, Package,Update,Iscancelled
,Result, Severity) and columns (JobID and RuleName ) fall under rule 2. we merge these two rows in to a single row and keep in that in the table.
2) Then the resulting row is again merged with the second row which is present above by applying the rule 1 and rule 2 . Below would be output of merge operation.
Now there would be only two rows in the output . But these rows cannot be merged as the data doesn't satisfy the merge rules 2 . As Jobsource for the row 1 in the above output is "PresubmissionSource" which is not equal
to "PostSubmission" jobSource which is in row 2. So these two rows are left unmerged .So the above two rows would be the output of merge operation on my source data.
This process has to be repeated for all the rows in the table. As of now my table as 92 Million rows with 56 columns which need to be considered for merging rows. I replicated my scenario in 9 columns and 4 rows to understand better. -
Merge multiple rows into single row (but multiple columns)
How to merge multiple rows into single row (but multiple columns) efficiently.
For example
IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
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
65 affc 2 Location USA TX AUS Hilton 92305
65 affc 2 Stats 5510 42.7 46 9999
65 affc 2 Audit 1996 July 172 1100
where different attributes mean different thing for each Information_type.
For example for Information_Type=Location
Attribute_1 means Country
Attribute_2 means State and so on.
For example for Information_Type=Stats
Attribute_1 means Population
Attribute_2 means American Ethnicity percentage and so on.
I want to create a view that shows like below:
IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
ThanksHi,
That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
I hope this answers your question.
If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're 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 can i select some row from multiple row in the same group of data
I want to select some row from multiple row in the same group of data.
ColumnA
Column B
1 OK
1 NG
2 NG
2 NG
3 OK
3 OK
I want the row of group of
ColumnA if ColumnB contain even 'NG'
row , select only one row which Column B = 'NG'
the result i want =
ColumnA Column B
1 NG
2 NG
3 OK
Thank youThat's some awful explanation, but I think this is what you were driving at:
DECLARE @forumTable TABLE (a INT, b CHAR(2))
INSERT INTO @forumTable (a, b)
VALUES
(1, 'OK'),(1, 'NG'),
(2, 'NG'),(2, 'NG'),
(3, 'OK'),(3, 'OK')
SELECT f.a, MIN(COALESCE(f2.b,f.b)) AS b
FROM @forumTable f
LEFT OUTER JOIN @forumTable f2
ON f.a = f2.a
AND f.b <> f2.b
GROUP BY f.a -
Count the no.of rows without using count function
Hi,
How to count the no.of rows without using the count function?
Thanks,they won't be 100% accurate. You're correct, Bluefrog, but the same goes for doing a count(*) (depending on the size of the table, ofcourse):
the table being queried might be under DML (deletes/inserts), and the next count(*) might give different results.
Both approaches will never be 100% accurate.
But simply selecting num_rows will be much much faster than doing a count(*).
Counting the number of rows always reminds me of this ongoing discussion, by the way:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:127412348064#14136093079164 ;)
Usually knowing the number of records by approximatly is sufficient, imo. 1000000 or 1000007 records: I don't care, don't need to know that.
I've never needed to know the exact number of records in a table in my code, or been given a requirement that forced me to. -
Max value without using max() function
Hi
Is there any way to get the max value from a table without using MAX() function
Thankswell if you think about it i'm sure you'll find a solution
what does max(field) means, it simply is the value of the field where no other value of the same field that is > than this value exists.
consider the following :
table TAB(
fld NUMBER(5));
translate the logic and you'll have
select a.fld from TAB a where NOT EXISTS(select b.fld from TAB b where b.fld>a.fld) and rownum=1;
of course there are better ways i'm sure, you'll just have to figure'em out. -
Select extra row without using UNION ALL in pl/sql
Hi,
Can anyone tell me how to select extra row without using UNION or UNION ALL in pl/sql. Actually I want to have my o/p of query as partitioned by designation and ordered by salary and than one extra row which will contain the highest salary in a particular salary. My table has first_name,emp_id,designation and salary column. And I wnt the o/p as.
Mohinish,12212,SI,46000
Ram,11212,SSI,47000
Shyam,12133,SI,48000
Rick,9898,SI,46000
Rocky,12312,SSI,56000
Sariq,23948,SI,43000
Suman,12789,HR,49000
Sampy,12780,SI,46000
Parna,11111,HR,50000
Now the o/p should be.
Mohinish,12212,SI,46000
Rick,9898,SI,46000
Sariq,23948,SI,43000
Shyam,12133,SI,48000
Shyam,12133,SI,48000
Ram,11212,SSI,47000
Rocky,12312,SSI,56000
Rocky,12312,SSI,56000
Suman,12789,HR,49000
Parna,11111,HR,50000
Parna,11111,HR,50000
Thanks in AdvanceYou don't have to do a UNION or UNION ALL in PL/SQL but you would need to in SQL to get the desired output:
with data_recs
as (select 'Mohinish' first_name,12212 emp_id,'SI' designation,46000 salary from dual union
select 'Ram',11212,'SSI',47000 from dual union
select 'Shyam',12133,'SI',48000 from dual union
select 'Rick',9898,'SI',46000 from dual union
select 'Rocky',12312,'SSI',56000 from dual union
select 'Sariq',23948,'SI',43000 from dual union
select 'Suman',12789,'HR',49000 from dual union
select 'Sampy',12780,'SI',46000 from dual union
select 'Parna',11111,'HR',50000 from dual)
select first_name, emp_id, designation, salary from data_recs union all
select s.first_name, s.emp_id, s.designation, s.salary
from (select first_name,
emp_id,
designation,
salary,
row_number() over (partition by designation order by salary desc) high_salary
from data_recs
order by designation, salary) s
where s.high_salary = 1
order by designation, salary;
FIRST_NAME EMP_ID DESIGNATION SALARY
Suman 12789 HR 49000
Parna 11111 HR 50000
Parna 11111 HR 50000
Sariq 23948 SI 43000
Rick 9898 SI 46000
Mohinish 12212 SI 46000
Sampy 12780 SI 46000
Shyam 12133 SI 48000
Shyam 12133 SI 48000
Ram 11212 SSI 47000
Rocky 12312 SSI 56000
Rocky 12312 SSI 56000 -
I want to configure the 7330 motion controller without using MAX
I am new to labview and I have a project where I have to configure the 7330 motion controller without using MAX. What do I need to do to get started doing so?
Thanks for the help!
nw2labviewHi,
There are several VI's that are included with the motion driver for configuring your controller. They are located on the function pallete under Vision and Motion>>Ni-Motion>>Axis Configuration. Using these VI's you will be able to configure your axis. But why don't you want to use MAX? If you are new to LabVIEW I would suggest configuring and testing your motor in MAX first before you start programing. Once you have it working there you may want to look at several of the examples such as Simple One-Axis Move.vi. I hope this helps.
GG -
Is it possible to create .ncd file without using MAX?
Is it possible to create .ncd file without using MAX? I am trying to read the data given by hundreds of possible Arb. IDs on one of the CAN port without having to create it from the MAX.
Thank youHi,
the NI-CAN driver software does not provide functions/VIs to generate
*.ncd files. However the *.ncd file format is just plain XML (ASCII text). Take a
look at the example.ncd file that gets installed with NI-CAN
(<ProgramFiles>\National Instruments\NI-CAN\):
<?xml version="1.0" encoding="UTF-8"?>
<nican_config version="0.1">
<saved>8/8/2005,17:58</saved>
<message name="TransmissionFluids">
<id extended="0">82</id>
<dbc>C:\Program Files\National Instruments\NI-CAN\example.ncd</dbc>
<conflicts>0</conflicts>
<bytes>6</bytes>
<interface>1</interface>
<comment></comment>
<channel name="ClutchPressure">
<conflicts>0</conflicts>
<bitfield start="0" bits="8" order="0" type="1"/>
<linear_scaling factor="1.600000e+001"
offset="0.000000e+000" max="4.000000e+003" min="0.000000e+000"
default="0.000000e+000" unit="kPa"/>
<comment></comment>
</channel>
</message>
</nican_config>
Thus, you could generate *.ncd files with simple file I/O. Having XML-specific file I/O functions simplifies this task.
-B2k -
ADF multiple row selection using checkbox
One of the basic feature missing in ADF 11g is multiple row selection using checkbox (ADF supports multiple row selection by CTRL+CLICK) and business users doesn't like the idea of CTRL+CLICK especially when the volume of click is more. Our requirement is to show the records as selected, on click of checkbox. We implemented multiple row selection by giving a checkbox and on submission, iterate all the rows and filter only selected rows for further processing. The approach works fine,but it is very slow when the volume of data is more, say 10 thousand rows. For 4 thousand records, iterating everything takes more than 200 secs !
Had the multiple row selection been the ADF standard way using CTRL+CLICK, and retrieving the selected rows using method theTable.getSelectedRowKeys() works much faster (completes in millisecs for 4 thousand records). Somehow ADF fetches the selected records much faster this way. Our requirement is on click of the checkbox, the ADF should select the records ( the same way it is doing CTRL+CLICK) and all such selected rows should be retrievable using the ADF method theTable.getSelectedRowKeys()
Is there any way it can be done?
Regards,
Antony.Hi All,
We have implemented the select and select all using check-box and it is working fine. Issue here is the performance is too slow
Assume SelectValue is the VO coulmn for the checkbox to select the values. To filter out the selected rows, we use the following line
Row[] pidRows = pidView.getFilteredRows("SelectValue", Boolean.TRUE);
it is very taking more than 2 minutes if the total number of rows are *4 thousands* and only if 2 rows are selected.
Whereas with the CTRL+CLICK standard approach, ADF has a built in API theTable.getSelectedRowKeys(); to get only the selected rows, and the built in API takes only few milliseconds to get the selected rows. Users are not agreeing to the CTRL+CLICK approach as it is not user friendly. Suggest if there is a way to make the select box to make it work the same way as CTRL+CLICK.
code snippet to do the standard way :
RowKeySet sk = theTable.getSelectedRowKeys();
_logger.info("row count of select "+sk.getSize());;+
Iterator selection =sk.iterator();
EmpVORowImpl empRow = null;
+while (selection.hasNext()) {+
Object rowKey = selection.next();
theTable.setRowKey(rowKey);
rowdata = (JUCtrlHierNodeBinding)theTable.getRowData();
empRow = (EmpVORowImpl)rowdata.getRow();
_logger.info("Emp # "+empRow.getEmpno() +" Emp Name : "+empRow.getEname() +" Is selected ? "+empRow.getisChecked());+
+}+ -
I guess I was not clear.....my fault....let me re-phrase: frequently I send an email to multiple contacts.....I'm constantly changing my selection of multiple contacts so using the "group" function doesn't get the job done.......so how can I go through my list of contacts and quickly select those contacts that I want to receive that particular email....thx
You need an app that allows group messaging. Enter group messenger in the search bar in the app store.
-
Merging multiple rows into a string without loop
Hi,
Wanted to know if there is a way we can merge the result set for a query(single column) into a string ?
For example, I have the following query which returns multiple rows:
SELECT organization_code
FROM mtl_parameters
WHERE oganization_id IN ( 1,2,3)
Lets say the result set for this is :
A
B
C
I want the data as A,B,C
Basically I will be fetching the organization_ID from a diff sub query. I know I can do it using for loop and keep appending the values.
But wanted to know if there is any easier way of doing it.Try this
SELECT ''||SUBSTR (SYS_CONNECT_BY_PATH (organization_code , ','), 2)||'' csv
FROM (SELECT organization_code
, ROW_NUMBER () OVER (ORDER BY organization_code
) rn,
COUNT (*) OVER () cnt
FROM mtl_parameters
WHERE oganization_id IN ( 1,2,3)
WHERE rn = cnt
START WITH rn = 1
CONNECT BY rn = PRIOR rn + 1;
Maybe you are looking for
-
Can't install updates to hard drive
I am also having difficulty with my wireless connection after recent upgrades, and have been attempting to reinstall both Airport Extreme Update 2007-03 and Mac OSX Server Update 10.4.9 to see if this will solve the problem. However, each time I atte
-
Can you change the size of the sample text in the character window in photoshop CC?
it appears that the ability to enlarge the sample text size has been demoed from cs7 and photoshop CC?
-
Install Acrobat 9 Standard on line
I have a new computer with no optical drive, only solid state storage. How do I download my product on line? thank you kindly.
-
How to get the Component id (HTMLB id)
Hi all, I created an application that has two list boxes and one commend button. While clicking the button I need to know how many list items in the list box. Is this possible? Anybody can guide me for this. Helpful answer will appreciate. Thanks & R
-
Monitor display issues: what would cause the monitor to show really off colors?
When booted from my DVD startup disk the colors are fine. When using the computers startup, the colors are like a 35mm film negative. Any ideas out there?