Help of the complex select query (Group by)
HelloI am in need of your help to create a unique select query for the data in the table below and whose output requies. I use oracle 10g on RHEL 5 version.
create table bustour (number of bussno (4), start_date date, number (2)) passenger;
ALTER session set nls_date_format = "dd-mm-yyyy";
insert into bustour values (4123, April 10, 2009 ", 20);
insert into bustour values (4123, may 10, 2009 ", 25);
insert into bustour values (4123, may 10, 2009 ', 18);
insert into bustour values (4123, June 10, 2009 ', 15);
insert into bustour values (6138, March 10, 2009 ', 16);
insert into bustour values (' 6138, March 10, 2009 ", 19);
insert into bustour values (6138, April 10, 2009 ', 22);
insert into bustour values (' 6138, April 10, 2009 ", 13);
insert into bustour values ("4123, July 10, 2009 ', 23);
insert into bustour values (4123, August 10, 2009 ", 27);
insert into bustour values (4123, November 10, 2009 ', 15);
insert into bustour values (6138, may 10, 2009 ', 16);
insert into bustour values (6138, may 10, 2009 ', 13);
insert into bustour values (6138, may 10, 2009 ', 18);
insert into bustour values (' 6138, may 10, 2009 ", 24);
insert into bustour values (6138, July 10, 2009 ", 20);
insert into bustour values (6138, August 10, 2009 ", 18);
SQL> select * from bustour;
BUSSNO START_DATE PASSENGERS
---------- ---------- ----------
4123 04-10-2009 20
4123 05-10-2009 25
4123 05-10-2009 18
4123 06-10-2009 15
6138 03-10-2009 16
6138 03-10-2009 19
6138 04-10-2009 22
6138 04-10-2009 13
4123 07-10-2009 23
4123 08-10-2009 27
4123 11-10-2009 15
BUSSNO START_DATE PASSENGERS
---------- ---------- ----------
6138 05-10-2009 16
6138 05-10-2009 13
6138 05-10-2009 18
6138 05-10-2009 24
6138 07-10-2009 20
6138 08-10-2009 18
17 rows selected.
I want query output as below :
Bussno start_date end_Date totalpassengers maxpessenger maxpassdate
4123 04-10-09 06-10-09 78 25 05-10-09
6138 03-10-09 04-10-09 70 22 04-10-09
4123 07-10-09 11-10-09 65 27 08-10-09
6138 05-10-09 08-10-09 109 24 05-10-09
So that we can know on what particular travel calendar, we have obtained maximum passengers and the date. (For calculating % of bonus driver)Please help me to write the query.
Best regards
Nisha
OK, something like this:
with my_tab as (select 1 id, 4123 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 20 passengers from dual union all
select 2 id, 4123 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 25 passengers from dual union all
select 3 id, 4123 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual union all
select 4 id, 4123 busno, to_date('06/10/2009', 'dd/mm/yyyy') start_date, 15 passengers from dual union all
select 5 id, 6138 busno, to_date('03/10/2009', 'dd/mm/yyyy') start_date, 16 passengers from dual union all
select 6 id, 6138 busno, to_date('03/10/2009', 'dd/mm/yyyy') start_date, 19 passengers from dual union all
select 7 id, 6138 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 22 passengers from dual union all
select 8 id, 6138 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 13 passengers from dual union all
select 9 id, 4123 busno, to_date('07/10/2009', 'dd/mm/yyyy') start_date, 23 passengers from dual union all
select 10 id, 4123 busno, to_date('08/10/2009', 'dd/mm/yyyy') start_date, 27 passengers from dual union all
select 11 id, 4123 busno, to_date('11/10/2009', 'dd/mm/yyyy') start_date, 15 passengers from dual union all
select 12 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 16 passengers from dual union all
select 13 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 13 passengers from dual union all
select 14 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual union all
select 15 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 24 passengers from dual union all
select 16 id, 6138 busno, to_date('07/10/2009', 'dd/mm/yyyy') start_date, 20 passengers from dual union all
select 17 id, 6138 busno, to_date('08/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual)
-- end of mimicking your data; use SQL below:
select busno,
min(start_date) start_date,
max(start_date) end_date,
sum(passengers) total_passengers,
max(passengers) max_passengers,
max_pass_date
from (select id,
start_date,
busno,
passengers,
distance,
max(start_date) keep (dense_rank first order by passengers desc) over (partition by distance, busno) max_pass_date
from (select id,
start_date,
busno,
passengers,
-- using tabibitosan method, borrowed from Aketi Jyuuzou
dense_rank() over (order by id) -
row_number() over (partition by busno order by id) distance
from my_tab))
group by busno, distance, max_pass_date
order by min(id)
BUSNO START_DATE END_DATE TOTAL_PASSENGERS MAX_PASSENGERS MAX_PASS_DATE
---------- ---------- ---------- ---------------- -------------- -------------
4123 04/10/2009 06/10/2009 78 25 05/10/2009
6138 03/10/2009 04/10/2009 70 22 04/10/2009
4123 07/10/2009 11/10/2009 65 27 08/10/2009
6138 05/10/2009 08/10/2009 109 24 05/10/2009
Tags: Database
Similar Questions
-
Helps the complex expression to Group By
Hi all
I use a BPM opensource to store variables in a Workflow process. Variables are stored in an Oracle 10 database and can be retrieved using the native Api of BPM (Java) or by using Sql. For performance reasons, I use simple SQL to collect a list filtered workflow variables.
Here is a simplified version of the BPM_INSTANCE Table:
[NAME] [VALUE] [PROCESS_INSTANCE]
=====================================
AREA IN ADDITION TO 1 125
ACME CUSTOMER 125
ID_WO 500 125
2 200 FIELD
200 TEST CLIENT
ID_WO 501 200
1 225 FIELD
CUSTOMER MODEL 225
ID_WO 502 225
Each PROCESS_INSTANCE has a set of variables that have a NAME and a VALUE.
My need is to collect the list of all (500,501,502) ID_WO, PROCESS_INSTANCE belongs to a DOMAIN (ex. 1) and one client (e.g. ACME)
I started coding the SQL:
Select VALUE from BPM_INSTANCE where NAME = 'ID_WO' and PROCESS_INSTANCE in
(select PROCESS_INSTANCE from BPM_INSTANCE, whose NAME = "CUSTOMER" and VALUE = "ACME"
)
However, I am not able to meet several conditions (for example I need also the PROCESS_INSTANCE also contains an AREA = 1).
Can someone help me?
Thank you
FrankHello
Would this work:
with data as ( select 'AREA' as name, '1' as value, '125' as pi from dual union all select 'CLIENT' , 'ACME', '125' from dual union all select 'ID_WO', '500', '125' from dual union all select 'AREA', '2', '200' from dual union all select 'CLIENT', 'TEST', '200' from dual union all select 'ID_WO', '501', '200' from dual union all select 'AREA', '1', '225' from dual union all select 'CLIENT', 'DUMMY', '225' from dual union all select 'ID_WO', '502', '225' from dual) select o.value, i.value, ii.value from data o inner join data i on ( o.pi = i.pi ) inner join data ii on ( o.pi = ii.pi ) where o.name = 'ID_WO' and i.name = 'AREA' and ii.name = 'CLIENT';
HtH
Johan -
Is it possible to delete a plot with the help of the mouse select the chart control?
For example, when I use the plot to draw thousands of lines on the chart control, I want to delete some of them, but there are thousands of generated plotHandle.
How can I get the plotHandle of the specific line on the chart control with the help of the mouse to select the option?
If I save the information from the lines, such as the plotHandle and the coordinates on a table or list, etc, I compare information lines for the plotHandle of the specific line.
Is it all a user-friendly way to remove a track selection on the chart control?I can't give you a reasonable way to solve this problem, since as you have already noted plot do not snappable plots.
A possible warkaround would be to replace the plot of individual instructions with a PlotXY matching with 2 bays 2 points each, which correspond to the x 1, x 2, y1, y2 parameters to plot. PlotXY plots are snappable, so you can enable this procedure select the plot and remove it.
-
A loop using the SQL select query.
Hello
I wanted to know, if the concept of loop is possible thanks to the SQL select statement.
For example
=======
Table T1
Col1 Col2
Slim 10
I want to write a query in such a way, so that when I get the result of the query, I format below.
Col1 Col2
Slim 10
Slim 10
Slim 10
Basically what I'm trying to achieve is, I have a table with two columns and it has a single line displayed above.
I want to display this line several times as the output of my SELECT query.
Let me know, if this target is achievable.
Kind regards
SaurabhLike this?
SQL> SELECT 10 col1, 'Sourabh' col2 2 FROM DUAL 3 CONNECT BY LEVEL <= 3; COL1 COL2 ---------- ------- 10 Sourabh 10 Sourabh 10 Sourabh SQL>
-
Need help with the curve of a group of objects
Salvation Group;
This is my first post in this group. I'm quite new to Adobe Illustrator CS5, and I had to start using it to provide the type of file to a printer for Sublimation in the USA. They use CS5, and all colors are limited to the Pantone Solid Coated for their printing system. I'm swimsuit fabric printing.
However, my question is probably very basic. It is also frustrating, because I have already successfully did this that I ask, just do not remember how I did it.
In my image, the upper rectangle has curved shape finished (bottom). I've done this before, with in fact several objects together. They all have the curve with the rectangle.
I tried to do it again, using all kinds of transformation tools (shear), the tools of the effect and everything I could find, but nothing has worked. I thought that maybe to shear would work if I could fix in the middle of the rectangle and shear on both sides of the rectangle to the top, but it does not work. I think I'll start to take notes when I find something that works!
How this simple curves of single object or group of objects? It can be done, I know!
Thank you, Tom.
You can also use the Suspender Warp or distort the Emvelope > make with Warp Arc
How to apply it
as individual objects and the other as a group
As objectrs
As a group
-
Help returns the array of query results
Hi all... Pretty new to this so please forgive my ignorance. Running Oracle 11 g, trying to return results as in the example I give below. I don't know how the Sport field will have unique values, and I don't know how many unique values the year field is seen in the data. Does anyone have recommendations/suggestions?
The structure of the table is:
Year of sport
Baseball 10-11
Football 10-11
Football 11-12
Football 11-12
Football 11-12
Baseball 11-12
The result should be sports in each year and should be grouped by year but shown as columns so:
(GROUP OF the year)
1, baseball 1, Football
2, 1, Football Soccer 1, Baseball
I hope that makes sense. Thanks for any help!
... KaelonDoes anyone have recommendations/suggestions?
Maybe something like:
SQL> with t as ( select 'Baseball' sport, '10-11' year from dual union all select 'Football', '10-11' from dual union all select 'Football', '11-12' from dual union all select 'Football', '11-12' from dual union all select 'Soccer', '11-12' from dual union all select 'Baseball', '11-12' from dual ) -- -- select year, listagg(cnt || ', ' || sport, ' ') within group (order by cnt desc) sports from ( select count(*) cnt, sport, year from t group by sport, year) group by year / YEAR SPORTS ------- ---------------------------------------- 10-11 1, Baseball 1, Football 11-12 2, Football 1, Baseball 1, Soccer 2 rows selected.
?
-
Help simplify the complex vectors?
Hi all, I am a very experienced noob when it comes to illustrator, and I'm looking for help with a problem... I hope a very simple.
I have an illustration that I'm about to print, but it's a vector very complex and I would like to simplify... Here is a picture with all the layers/elements...
I try to simplify it so that I find myself with an image as follows:I don't want to just not all individual items, which create a headache, if I try to print vinyl, etc.
Anyone got any advice for me?
Pathfinder (the Committee), let us unite should do.
-
Help at the waterfall "select choice".
Hello
I tried to create a JSF page with 2 commands 'Select one choice' A and B. The contents of the control B depend on the selection made on the control. So far what I have is control B displays the contents of the related data of the first element on the control, but if I change the selection on the control B does not change its content.
What are the steps to create a pair controls 'Select' cascading in a JSF page?
Command has must indicate the attribute X table X.2
Control B to display the attribute table Y.2 Y
Attribute X 1 is a primary key
Y.3 attribute is a foreign key (of the X.1 attribute)
Y.1 attribute is a primary key
Can I use read only views?
Thank you.Hello
the steps are
-define autosubmit = true on selectOneChoice 1
-Have a ValueChangeListener who gets the selected value and who uses it to set the query for the dependent list condition
-use AdfFaces.getCurrentInstance () .addPartialTarget () to update the first list For 10.1.3 I docmented in the document, you can download it here: http://thepeninsulasedge.com/frank_nimphius/wp-content/uploads/2008/05/OldAndLostBlogBusterTips.zip
See pages 323 and 332
Frank
-
Help on the game of query results
Hi gurus,
Have this survey for my requirement of dataset sql.
Sample, it's that I have to pick up the nonfunctional currency transactions.
Lets say for a given month, data that are present are for CurrencyA and CurrencyB for a particular account.
Account1 has a transaction does not work CurrencyA and CurrenyB then Account2 has only transaction to CurrencyB.
My current query result is that the 3 first lines, what I need is the 4th should also appear and be included.
CurrencyA - amount - account1
CurrencyB - amount - account1
CurrencyB - amount - Account2
CurrencyA - < '0' / or null >-Account2
I think that my request is based on the currency < x > I have, so it should be for each account, he has all the lines for each currency.
If please notify and let me know your thoughts.
Kind regards
Hello
It looks like you want an outer join partitioned.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
Help - run the extended CO query?
Read the many threads on the topic prior to this announcement, but im still stuck.
I extended a sowing controller, to display text msgStyle seeded as a link under certain conditions.
I want to take is:
If (condition true) {//set the text msg destination uri} otherwise do nothing
To implement the condition, I have to make a request to check if this value exists in the table. I have not any Vo attached to achieve this.
I could create a custom VO and attach it to AM programaticaly? One last thing - AM attached to this seeded page is am root.
I read that AM root should not be extended.
How can I achieve this?Hello
For this, you can use dynamic VO, create VO, and run the query.
Kind regards
Out Sharma -
Formatting of the Select query
The following select query returns the data in green. How do I format to return the path that it is formatted in red?
Basically, if FIELD1 is "Customer A" and FIELD2 is "Gas" then I back to 'New customer' Field1 and Field2 'gas '. If 'Customer E' FIELD1 and FIELD2 is 'Total' then it should return 'E rejection' in Field1 and 'Prod_Discharge' in the Field2.
Please let me know if my question is not sensible or need to be clarified.
SELECT
DECODE (Field1, 'Nine', ' A', 'Old', 'E', 'Term', 'F', Field1)
DECODE (Field2, 'Prod', 'Gas', Field2)
Customers
FIELD1 FIELD2
Customer A gas
Customer has oil
Total customers E
Customer F Total
Need to format as follows:
Field1 Field2
New gas customer
New customer oil
E Prod_Discharged releases
F Prod_Discharged releases
Try this:
SELECT CustomerID
, CASE WHEN field1 = 'Customer A' THEN 'new customer '.
WHEN field1 = 'Customer E' AND field2 = 'Total' THEN 'E releases '.
WHEN field1 = ' customer F ' AND field2 = 'Total' THEN 'F performs ".
Of ANOTHER Field1
FIELD1 AS END
, CASE WHEN Field1 IN ('E of customer', ' customer F ') AND field2 = 'Total' THEN 'Prod_Discharged '.
Of OTHER Field2
END AS FIELD2
Status
Customers
;
-
Help with the query to return the results of the group in the table?
Hello
Im a total noob, so please be nice...!
I'm looking around a table contains a column of WORD and a WORD_TYPE_ID column.
Words can have the same type_id.
What I'm trying to do is to write a query that will return the longest word for each word_type_id.
I tried for hours to get it and everything seems to get is two error messages or just the longest word in the whole WORD column.
Is the furthest I can get before things break down...
Select Word
table
where
Length (Word) =
(
Select
Max (length (Word))
table
)
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
Thank youHello
Welcome to the forum!
Here's one way:
SELECT word_type_id , MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word FROM table_x GROUP BY word_type_id;
If there be a tie in some word_type_id (i.e. 2 or more words have exactly the same length, which is the longest in this group) the expression above will return the first one alphabetically. (This is what means here MIN.)
Published by: Frank Kulash, 11 August 2009 13:56
You almost had it.
As you have noticed, you get the longest line across the table. This is because your subquery was watching the entire table.
If you to correlate the subquery to the row in the main table, as shown below, you can get the longest word in each group:select word from table m -- m for main where length (word) = ( select max (length(word)) from table where word_type_id = m.word_type_id -- New );
-
Need help with the use of GROUP BY in a select statement UNION
I am writing a query that allows to combine a legacy system that interfaces it is trial balance in the Oracle of R12 GL. It was only meant to continue for a month or two, but it is likely to continue for 6 months. Please Auditors Auditors, to provide proof that the system is in balance with Oracle GL. By my verification requirements, I need to make a full reconciliation from the month of conversion (life in the amount of date), then PTD for each month.
The legacy account is placed in attribute1 on the lines of the journals. Uses of the old system balancing segments that are also used on the platform in Oracle for this division, i.e., Procure-to-Pay has been cut over Oracle, but not everything yet. So, I can't count on the GL_BALANCES table for the info, I get from the JE_LINES.
My problem is not the only request for the month. But when I try to combine the queries with a Union, to aggregation of each measurement period in its own column, the group is necessary after each selected instruction rather than allowing me to put at the end of the UNION. (When I put the group by at the end of the UNION, I have the 'not one group' function)
So I get duplicate for each month of discrete measure accounts. When I duplicate in my Oracle database accounts, I can't count on the VLOOKUP function in excel to exactly match an account of inheritance. I know there are more sophisticated ways to provide this output, but I'm hoping to get this info in a simple query.
Thank you in advance for any advice you can provide
Example of data output (the goal for me is to get the two rows to appear as one based on common points on the LEGACY_ACCOUNT and the ORACLE ACCOUNT
The LEGACY ACCOUNT ORACLE ACCOUNT JUN_15 JUL_15 AUG_15 SEP_15 OCT_15 NOV_15 DEC_15 010000001109000003584 190-600552-1001-100231-000-0000-0000-0000 0 0 -242961.04 0 0 0 0 010000001109000003584 190-600552-1001-100231-000-0000-0000-0000 0 192588.02 0 0 0 0 0 Here is a simplified version of my code that returns both records. In my research, I had found a number of conversations where it has been shown that the group could be put at the end of the select statement. However, when I remove the group from the first select statement I get SQL error: ORA-00937: not a function of simple-group
Select
l.attribute1 LEGACY_ACCOUNT,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | COMBINATION OF C.SEGMENT8,
JUN_15 TO_NUMBER('0').
JUL_15, sum (NVL(l.accounted_dr,0.00)-NVL(l.accounted_cr,0.00)),
TO_NUMBER('0') AUG_15.
TO_NUMBER('0') SEP_15.
TO_NUMBER('0') OCT_15.
TO_NUMBER('0') NOV_15.
DEC_15 TO_NUMBER('0')
Of
b GL.gl_je_batches,
GL.gl_je_headers h,
GL.gl_je_lines l,
GL.gl_code_combinations c,
GL.gl_je_sources_tl j
where b.je_batch_id = h.je_batch_id
and h.je_header_id = l.je_header_id
and l.code_combination_id = c.code_combination_id
and h.je_source = j.je_source_name
and c.segment1 ('190 ', '191', '192', '193', '194', ' 195 ', ' 196',' 197', ' 198 ', ' 199',)
('200 ', '203', ' 205', '206 ', '330', '331', '332',' 333 ', ' 334',' 335', ' 336 ', ' 337')
and j.language = 'en '.
and h.PERIOD_NAME ("JUL-15'")
Group
l.attribute1,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | C.SEGMENT8
UNION
Select
l.attribute1 LEGACY_ACCOUNT,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | COMBINATION OF C.SEGMENT8,
JUN_15 TO_NUMBER('0').
TO_NUMBER('0') JUL_15.
AUG_15, sum (NVL(l.accounted_dr,0.00)-NVL(l.accounted_cr,0.00)),
TO_NUMBER('0') SEP_15.
TO_NUMBER('0') OCT_15.
TO_NUMBER('0') NOV_15.
DEC_15 TO_NUMBER('0')
Of
b GL.gl_je_batches,
GL.gl_je_headers h,
GL.gl_je_lines l,
GL.gl_code_combinations c,
GL.gl_je_sources_tl j
where b.je_batch_id = h.je_batch_id
and h.je_header_id = l.je_header_id
and l.code_combination_id = c.code_combination_id
and h.je_source = j.je_source_name
and c.segment1 ('190 ', '191', '192', '193', '194', ' 195 ', ' 196',' 197', ' 198 ', ' 199',)
('200 ', '203', ' 205', '206 ', '330', '331', '332',' 333 ', ' 334',' 335', ' 336 ', ' 337')
and j.language = 'en '.
and h.PERIOD_NAME ("AUG-15'")
Group
l.attribute1,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | C.SEGMENT8
order by 1
Is there a good reason to make this period both as a series of trade unions? This looks like a classic pivot for me query. This will make a way through the tables and should get the desired results.
Select l.attribute1 legacy_account,
c.Segment1: '-' | c.Segment2: '-' | c.segment3: '-' | c.segment4: '-' |
c.segment5: '-' | c.segment6: '-' | c.segment7: '-' | combination of c.segment8,
sum (case when h.period_name = 'JUN-15'
then nvl(l.accounted_dr,0.00)-nvl(l.accounted_cr,0.00)
otherwise 0 end) jun_15,.
sum (case when h.period_name = 'JUL-15'
then nvl(l.accounted_dr,0.00)-nvl(l.accounted_cr,0.00)
otherwise 0 end) jul_15,.
- and similar to DEC - 15
GL.gl_je_batches b, gl.gl_je_headers h, gl.gl_je_lines l.
GL.gl_code_combinations c, gl.gl_je_sources_tl j
where b.je_batch_id = h.je_batch_id
and h.je_header_id = l.je_header_id
and l.code_combination_id = c.code_combination_id
and h.je_source = j.je_source_name
and c.segment1 ('190', '191', '192', '193', '194', '195',' 196', ' 197',
'198 ', '199', '200', '203', '205' ', 206',' 330 ', ' 331',
"332 ', '333', '334', '335',' 336 ', ' 337')
and j.language = 'en '.
and h.period_name (' Jun-15', ' 15 JUL', ' AUG-15'... "" ")
L.attribute1 group,
c.Segment1: '-' | c.Segment2: '-' | c.segment3: '-' |
c.segment4: '-' | c.segment5: '-' | c.segment6: '-' |
c.segment7: '-' | c.segment8
If you're on the 11G version of the database, you might want to look at the PIVOT keyword that will do the same thing in a more concise expression.
John
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
Ask for help with the query group by
Hello
I have the following table with values structure
I have the following requirement, the output should be:CREATE TABLE DUMMY ( SR_NUMBER VARCHAR2(100 CHAR), ASSIGNMENT_GROUP VARCHAR2(100 CHAR), REASSIGNMENT_COUNT VARCHAR2(100 CHAR), CREATED DATE, CLOSED DATE, TARGET_DATE DATE ) insert into dummy values('AAA','A','1','02-OCT-11','25-OCT-11','09-OCT-11'); insert into dummy values('ABC','A','1','03-SEP-12','26-SEP-11','10-SEP-11'); insert into dummy values('AVB','A','1','02-NOV-13','25-NOV-13','09-NOV-13'); insert into dummy values('AFT','B','1','02-OCT-11','25-OCT-11','09-OCT-11'); insert into dummy values('ACS','B','1','02-JAN-12','25-JAN-12','09-JAN-12'); insert into dummy values('AVC','B','1','02-OCT-13','25-OCT-13','09-OCT-13'); insert into dummy values('AAD','B','1','02-MAR-14','25-MAR-14','09-MAR-14'); insert into dummy values('AAA','C','1','02-OCT-11','25-OCT-11','09-OCT-11'); insert into dummy values('AAA','D','1','02-JUN-11','25-JUN-11','09-JUN-11'); insert into dummy values('AAA','E','1','02-APR-12','25-APR-12','09-APR-12'); insert into dummy values('AAA','A','1','02-FEB-13','25-FEB-13','09-FEB-13'); ?
Number of ticket (sr_number)
% of tickets inside the DL
Number of tickets inside the DL
Average cycle time (cycle time = closing date - date of creation)
Total cycle time (cycle time = closing date - date of creation)
Number of reallocations (sum)
DL - (deadline) formula is, closed date < = target_date
This should be displayed, grouped by year, then month, then the assignment group. The values must be in descending order (dates) is not sure that group in operation here.
I am able to write the code base of the foregoing, but group from the year, month, and group assignment is pretty confusing to me.
Can someone give me a voucher code...This may not give you exactly what you want, but if all goes well, it will give you something to work with:
WITH tickets AS ( SELECT TO_CHAR(created, 'YYYY') created_year, TO_CHAR(created, 'MM') created_month, assignment_group, COUNT(sr_number) ticket_count, AVG(closed - created) avg_cycle_time, SUM(closed - created) tot_cycle_time, COUNT(reassignment_count) reassign_count FROM dummy GROUP BY TO_CHAR(created, 'YYYY'), TO_CHAR(created, 'MM'), assignment_group ), dl_tickets AS ( SELECT TO_CHAR(created, 'YYYY') created_year, TO_CHAR(created, 'MM') created_month, assignment_group, COUNT(sr_number) ticket_in_dl_count FROM dummy WHERE closed <= target_date GROUP BY TO_CHAR(created, 'YYYY'), TO_CHAR(created, 'MM'), assignment_group ) SELECT t.created_year, t.created_month, t.assignment_group, t.ticket_count, NVL(dl.ticket_in_dl_count, 0) ticket_in_dl_count, NVL(dl.ticket_in_dl_count/t.ticket_count, 0) * 100 pct_ticket_in_dl_count, t.avg_cycle_time, t.tot_cycle_time, t.reassign_count FROM tickets t, dl_tickets dl WHERE t.created_year = dl.created_year (+) AND t.created_month = dl.created_month (+) ORDER BY created_year DESC, created_month DESC
Published by: user1983440 on May 27, 2013 15:47 - added reassign_count
Published by: user1983440 on May 27, 2013 15:54 - added ORDER BY
Maybe you are looking for
-
Apps quit properly or to force out
I had a strange problem on my macbook pro (el capitan 10.11.5, processor 2.5 GHz, 16 GB of memory, everything is completely up-to-date) where certain apps quit properly? as I press "quit" and everything will act as it's quit smoking and application d
-
Why I have to sign in to IgHome every time I open my browser?
I have two computers, one with xp and one with win 7. On xp, I open my browser and am ready to go. I click on gmail and my mail is opened. ON win 7 I have to connect to customize igHome and then signed to gmail to get the job. As the case with everyo
-
Cannot install update there is 9.2.1 on my iPad iOS installation error 2
Cannot install the update there is error install iOS 9.2.1 in my iPad 2
-
Desktop is now too big and cluttered with unnecessary icons
A friend recently installed Windows XP Professional. His office is now more size (it has vertical/horizontal scrollbars) & office space is filled with icons on every restart that he returned to a folder every time. How can this be addressed? (Thanks
-
Windows Update is now always ask to install the Vista SP2, which was installed years ago. When you try to install through Windows Update, it concludes the installation like ok, then once again it shows in Windows Update. When I try via stand-alone, i