Find the top 3 travellers per year

Hello
I created a single table where I store the ID of the loyalty, road ID as well as the Dates of vol. I have 5 frequent flyers in total and only 2 channels (to keep this small and concise for this exercise). I'm hoping to find the big TOP 3 passenger flight annually.

The output should be as follows:
Flight Year   Route ID    Frequent Flyer   Flight Count
=======================================================
2005               001              1001              5
2005               001              1002              3
2005               001              1003              3

2005               002              1004              7
2005               002              1005              5
2005               002              1001              1

2006               001              1002              7
2006               001              1003              5
2006               001              1001              1

2006               002              1005             11
2006               002              1003              1
2006               002              1004              1
Script for table
CREATE TABLE FLIGHTS
  (
    FREQ_FLYER_ID VARCHAR2(4), ROUTE_ID  VARCHAR2(3), FLIGHT_DATE DATE
  );
INSERT the Script for the table
-- 1001: 5; 1002: 3; 1003: 3; 1004: 1, 1005: 1
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1001','001',to_date('01-JAN-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1001','001',to_date('01-FEB-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1001','001',to_date('01-MAR-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1001','001',to_date('01-APR-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1001','001',to_date('01-MAY-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-JAN-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-FEB-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-MAR-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-APR-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-MAY-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-JUN-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1004','001',to_date('01-FEB-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1005','001',to_date('01-MAR-05','DD-MON-RR'));

-- 1001: 1; 1002: 0;  1003: 0, 1004: 7; 1005: 5
insert into flights (freq_flyer_id,route_id,flight_date) values ('1001','002',to_date('31-JAN-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1004','002',to_date('31-JAN-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1004','002',to_date('28-FEB-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1004','002',to_date('31-MAR-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1004','002',to_date('30-APR-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1004','002',to_date('31-MAY-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1004','002',to_date('30-JUN-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1004','002',to_date('31-JUL-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('30-APR-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-MAY-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('30-JUN-05','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-JUL-05','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1005','002',to_date('31-AUG-05','DD-MON-RR'));

-- 1001: 1; 1002: 7;  1003: 5, 1004: 0; 1005: 0
insert into flights (freq_flyer_id,route_id,flight_date) values ('1001','001',to_date('01-JAN-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-FEB-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-MAR-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-APR-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-MAY-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-JUN-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1002','001',to_date('01-JUL-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1002','001',to_date('01-AUG-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-APR-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-MAY-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-JUN-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1003','001',to_date('01-JUL-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1003','001',to_date('01-AUG-06','DD-MON-RR'));

-- 1001: 0; 1002: 0;  1003: 1, 1004: 1; 1005: 11
insert into flights (freq_flyer_id,route_id,flight_date) values ('1003','002',to_date('31-JAN-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1004','002',to_date('28-FEB-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-JAN-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1005','002',to_date('28-FEB-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-MAR-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1005','002',to_date('30-APR-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-MAY-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('30-JUN-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-JUL-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1005','002',to_date('31-AUG-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('30-SEP-06','DD-MON-RR'));
insert into flights (freq_flyer_id,route_id,flight_date) values ('1005','002',to_date('31-OCT-06','DD-MON-RR'));
Insert into FLIGHTS (FREQ_FLYER_ID,ROUTE_ID,FLIGHT_DATE) values ('1005','002',to_date('30-NOV-06','DD-MON-RR'));
Thanks in advance!

Hello

Here's one way:

WITH     got_r_num   AS
(
     SELECT    EXTRACT (YEAR FROM TRUNC (flight_date, 'YEAR'))
                                            AS flight_year
     ,       route_id
     ,       freq_flyer_id
     ,       COUNT (*)                   AS flight_count
     ,       RANK () OVER ( PARTITION BY  TRUNC (flight_date, 'YEAR')
                                   ,             route_id
                             ORDER BY      COUNT (*)     DESC
                      )                  AS r_num
     FROM      flights
     GROUP BY  TRUNC (flight_date, 'YEAR')
     ,            route_id
     ,       freq_flyer_id
)
SELECT    *     -- or list all columns except r_num
FROM       got_r_num
WHERE       r_num     <= 3
ORDER BY  flight_year
,            route_id
,            r_num
;

If there be a tie (in other words, if 4 or more people, some with exactly the same number of flights, all can to be in the top 3 for a given year and the road) then the above query will include all the contenders for the top 3. For example, if you add one more line of your sample data:

Insert into FLIGHTS (FREQ_FLYER_ID, ROUTE_ID, FLIGHT_DATE)
       values          ('1009',         '002',    to_date('30-NOV-2006','DD-MON-YYYY'));

Now, who are the top 3 flliers for 2006 on road '002'? Obviously, "1005" is one of them, but there is a tie of 3 - way for second place: '1003 ', '1004' and ' 1009' have exactly 1 flight, and all have equal calim to be in the top 3. Why would you exclude one of them, ratehr than the other two? The query above includes all the.
If you want to ensure that not more than 3 rows are included for the whole year and the road, and then add the columns of tiebreaker to analytical ORDER BY clause and/or use ROW_NUMBER instead of RANK.

This is called a Query Top - N , because you're gathering of N (N = 3 in this case) from the top of an ordered list.

Published by: Frank Kulash, December 17, 2012 12:52

Tags: Database

Similar Questions

  • To find the Top most parent SQL

    How to find the top most parent SQL. I want to avoid the hierarchical query that shows a high cost to run. Please suggest alternative options to find the parent

    Maybe (when having multiple hierarchy trees) to be adapted to your needs

    Select empno, I

    from (select empno, I

    WCP

    where empno = 7876

    model

    hierarchy of reference on (select employee empno,

    Manager Mgr

    WCP

    )

    dimension (employee)

    measures (Manager)

    main main_model

    size of (0 I)

    measures (empno)

    rules iterate (100) until (empno [iteration_number + 1] is null)

    (

    EmpNo [iteration_number + 1] = hierarchy.manager [empno [iteration_number]]

    )

    )

    where empno is not null

    order by I desc

    EMPNO I
    7839 3
    7566 2
    7788 1
    7876 0

    Concerning

    Etbin

  • Find the top level of a VM folder

    I want to find the name of the top-level folder that contains a virtual machine in a data center and looking for the root tree.

    For example \\datacenter\folder1\folder2\folder3\TestVM

    I try to find as a parameter of the TestVM folder1.

    I need to sort all the VM in our sphere of their top-level folder

    In all cases to do this would be appreciated.

    Also it would be quite in powercli with scripts

    Try something like this

    $vm = Get-VM -Name TestVM$object = $vm.ExtensionData$parent = Get-View $object.Parent
    
    while($parent -is [VMware.Vim.Folder] -and $parent.Name -ne "vm"){    $object = $parent    $parent = Get-View $object.Parent}$object | Select @{N="VM";E={$vm.Name}},    @{N="Top Folder";E={$object.Name}} 
    
  • Script to find the 'top 10' VMs consuming disk performance?

    We're troubleshooting an issue of storage and I'm looking for a better way to find virtual machines that consume disk peformance.  If I had a wish list, the script would be the 'top 10' VMs with the highest disk throughput and the e/s in the last 24 hours.

    Such a script exist?  Any help would be greatly appreciated.

    You can try the following one liner

    Get-VM | Select Name,
         @{N="AverageIO";
           E={($_ | Get-Stat -Stat disk.usage.average -Start (Get-Date).adddays(-1) | Measure-Object -Average -Property Value).Average}} | `
         Sort-Object -Property AverageIO -Descending | Select -First 10
    

    This example uses the metric of disk.usage.average but you can easily use any of the other measures related to the disc.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • How to find the difference in date in years, months and days

    Hello
    I need to find the difference between 2 dates in the following way "years months days". "
    Please can help me, how can I achieve this.

    for example, in the scott schema emp table, I need to find the difference in date between sysdate and hiredate for an employee in the following way.

    12 years 7 months 4 days.

    Hello

    Please, see this post to AskTom [difference between 2 dates | http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:96012348060]. There is good information in this forum, for example you can also see this thread [calculation of years, months & days | http://forums.oracle.com/forums/thread.jspa?messageID=3115216�]

    Kind regards

    Published by: Walter Fernández on November 30, 2008 08:58 - adding another link

  • algorithm to find the top of the parabola

    Use case: mower rejection of common-mode using a programmable potentiometer

    Problem: The performance of each circuit varies greatly and you are looking for best value (lowest CMRR) gives erroneous results. The performance seems to be relatively flat on some circuits, straight on others. Launching in the middle range of the potentiometer and moving upwards or downwards, I compare the measured value after the change of the potentiometer to the last measured value. By doing this I can get for the lowest CMR.

    Setup: entry wave sign 5V 60 Hz on both positive and negative of a differential ADC. The potentiometer is cut and reduces common-mode noise. Go away and the common-mode noise increases.

    Question: I would like to use adjustment curve to calculate the shape of the performance of the CMR. Take several steps (no more than 10 then I hope). Get the x y (x = 0 to 1023 trim adjustment potentiometers, Y = amplitude of the measured signal common-mode). Find the vertex.

    Is this possible and can someone point to an example.  I have not found one.

    A parable is a second order polynomial curve.  The Summit must be the peak value.  The general polynomial Fit.vi to maintain your data. The Coefficients of the polynomial outputs to calculate the location of the tip with a DAB of analytic geometry.

    Edit: Note that you may need to do checks to make sure that your data has not generated any curve as a parable.

    Lynn

  • Try to find the railways assets numbers per Lun

    I try to find the number of active paths to just a single Lun, to control if I had a fiber optic connection down. I keep fit in a corner, because at the first right with a Get-view of a host and fish around in the multipathsection. But really I just want to test 1 Lun on all my guests to see how active paths each host has it. And it seems that orders of the Get-ScsiXX you can not specify a single lun.

    Am I confused somewhere?

    Have you tried it like that

    $canonicalname = "naa.600507540180809ef0000000000001ba" $esx = Get-VMHost -Name MyEsx
    Get-ScsiLun -VMHost $esx -CanonicalName $canonicalname | Select CanonicalName,  @{N="Active Paths";E={Get-ScsiLunPath -ScsiLun $_ | where {$_.State -eq "active"} |  Measure-Object | Select -ExpandProperty Count}}
    
  • find the top shared appl

    How will I know that an appl system has a shared Top APPL?

    Hello

    How will I know that an appl system has a shared Top APPL?

    View post:
    How to find applications are shared or not

    Thank you
    A H E E R X

  • Find the archive logs generated per day (for 7.3.4 database)?

    I use a query like the one below to determine the average amount archives logs generated per day for a database for a month:

    Select sum (GB_USED_PER_DAY) count (GB_USED_PER_DAY) in (SELECT
    To_char(completion_time,'YYYY-mm-DD') completion_date,
    round (SUM (block_size *(blocks+1)) / 1024 / 1024 / 1024, 2) GB_USED_PER_DAY
    V $ archived_log
    WHEN TRUNC (completion_time) BETWEEN
    TRUNC(SYSDATE-30) AND TRUNC (SYSDATE)
    GROUP OF TO_CHAR(completion_time,'YYYY-MM-DD')
    order by 1 desc);

    This query does not work on Oracle 7.3.4 database. Anyone know how I can calculate average archive generation of newspapers per day for Oracle 7.3.4?

    Thanks in advance!

    Select substr(first_time,1,8), round (sum (bytes) /(1024*1024)) MB of v$ log group by substr (first_time, 1, 8);

  • Tips to find the "top talkers" on Cisco ASA

    Y at - it a command that displays the users that use the most bandwidth? Or I need a 3rd party app that monitors the pipe? I basically am noticing a spike in bandwidth consumption from time to time and have no way to easily identify the culprit. Any suggestions would be greatly appreciated.

    Jeff

    Apart from the typical SSL the ASDM had a major overhaul. It now includes a firewall dashboard where you can see rules for superior access, services, hosts etc.

  • How can I find the top row of a single table, split among several images in each image.

    Hi all.

    Thanks in advance.

    You can browse all the cells in a row column * and ask the first insertion of a text on his cell point user.user parentTextFrames [0].

    If the ID value has changed, the cell is in a different text frame. As well as its line.

    CC-2015, it might be a little different, because we have a new type of cell: CellTypeEnum.GRAPHIC_TYPE_CELL (not insertionPoints pave the way).

    You can also:

    Reproduce all text blocks in history, in that the table is sitting and control for unique tables in duplicates.

    Uwe

    * edit

  • DENSE_RANK and find the top three rows return regardless of their rank.

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    Hello

    I have the following problem;

    Dense_rank using I've categorized the trees in a plot of height.

    Now I need to filter the first three records by parcel based on the position of the trees, it's complicated by the fact that sometimes two or three of the three tallest trees have the same height.

    Records that I want to use for the parcel number 90001 are tree numbers 4, 5 and 3.

    Records that I want to use for the parcel number 31000 are tree numbers 4, 5, and 3, but rather the number 2 shaft is included.
    select distinct plot_number
         , tree_number
         , tree_height
         , dense_rank() over (partition by plot_number order by tree_height desc)ht_rank
      from tst_rank
      order by plot_number, ht_rank asc
    ;
    
    PLOT_NUMBER TREE_NUMBER TREE_HEIGHT HT_RANK
    ----------- ----------- ----------- -------
          31000           4          10       1 
          31000           5          10       1 
          31000           3           3       2 
          31000           2           2       3 
          31000           1           1       4 
          90001           5          20       1 
          90001           4          10       2 
          90001           3           3       3 
          90001           2           2       4 
          90001           1           1       5 
    
     10 rows selected 
    The dense rank function allows me to classify the trees, but then it has accomplished its purpose. The following query is an example of what I want to do - but - I need to access the 3 early accounts after the rankings were made, so the following query is not going to use the collation.
    select plot_number
         , max(decode(ht_rank, '1', tree_height*100)) ht_1
         , max(decode(ht_rank, '2', tree_height*100)) ht_2
         , max(decode(ht_rank, '3', tree_height*100)) ht_3
    from (select distinct plot_number
               , tree_number
               , tree_height
               , dense_rank() over (partition by plot_number order by tree_height desc)ht_rank
            from tst_rank
           order by plot_number, ht_rank asc
          )txt  
     group by plot_number
    ;
    
    PLOT_NUMBER HT_1 HT_2 HT_3
    ----------- ---- ---- ----
          31000   10    3    2 
          90001   20   10    3 
    But I want to see;
    PLOT_NUMBER HT_1 HT_2 HT_3
    ----------- ---- ---- ----
          31000   10   10    3 
          90001   20   10    3 
    Anyone have some ideas of what I could do to get there?

    See you soon
    Ben


    Create script to replicate my problem;
    -- drop table tst_rank;
    
    CREATE TABLE TST_RANK
    ( PLOT_NUMBER NUMBER
    , TREE_NUMBER NUMBER
    , TREE_HEIGHT NUMBER
    );
    
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('31000','1', '1');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('31000','2', '2');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('31000','3', '3');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('31000','4', '10');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('31000','5', '10');
    
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('90001','1', '1');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('90001','2', '2');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('90001','3', '3');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('90001','4', '10');
    INSERT INTO TST_RANK (PLOT_NUMBER, TREE_NUMBER, TREE_HEIGHT) VALUES ('90001','5', '20');
    
    COMMIT;
    
    /*
    
    select distinct plot_number
         , tree_number
         , tree_height
         , dense_rank() over (partition by plot_number order by tree_height desc)ht_rank
      from tst_rank
      order by plot_number, ht_rank asc
    ;
    
    select plot_number
         , max(decode(ht_rank, '1', tree_height)) ht_1
         , max(decode(ht_rank, '2', tree_height)) ht_2
         , max(decode(ht_rank, '3', tree_height)) ht_3
    from (select distinct plot_number
               , tree_number
               , tree_height
               , dense_rank() over (partition by plot_number order by tree_height desc)ht_rank
            from tst_rank
           order by plot_number, ht_rank asc
          )txt  
     group by plot_number
    ;
    
    */
    Published by: benton on 9 October 2012 14:45

    Use ROW_NUMBER

    SQL> select plot_number,
      2         max(decode(rn,1,tree_height)) h1,
      3         max(decode(rn,2,tree_height)) h2,
      4         max(decode(rn,3,tree_height)) h3
      5  from(
      6  select plot_number,tree_height,
      7         row_number() over(partition by plot_number order by tree_height desc) rn
      8  from tst_rank)
      9  group by plot_number;
    
    PLOT_NUMBER         H1         H2         H3
    ----------- ---------- ---------- ----------
          31000         10         10          3
          90001         20         10          3
    
  • Find the top level element in SQL

    Hi all
    I have a table with the following format. item_id, sup_item_id and a few other columns.

    And that's the real problem:
    We have parts (elements) mounted in designed, says let cars for example. also is it a tyre_1 element with car_A, car_B and car_C have entries in the table like this
    item_id sup_item_id
    tyre_1 car_A
    tyre_1 car_B
    tyre_1 car_C

    but sometimes we are small element in someother element, then it goes to the main product. For example, we adjust wire_1 in circuit_1 which then goes to car_A and car_B. This number can have any levels and wire_1 can be in any number of circuits.
    If the data table will be like this
    item_id sup_item_id
    wire_1 circuit_1
    wire_1 circuit_2
    circuit_1 car_A
    circuit_1 car_B

    You can identify high most of the elements in the table because they have no value in the sup_item_id field.
    item_id sup_item_id
    car_A
    car_B

    so, I want to write a sql to discover all the elements of highest level of the page for a given part. Can someone help me with this.

    I think that's what you're looking for
    "Rim_1", I took as a point of entry

    with data as
    (
    select 'bolt_1' item_id,'rim_1' sup_item_id from dual union all
    select 'rim_1' item_id,'tyre_1' sup_item_id from dual union all
    select 'tyre_1' item_id,'frame_1' sup_item_id from dual union all
    select 'frame_1' item_id,'car_1' sup_item_id from dual union all
    select 'rim_1' item_id,'car_2' sup_item_id from dual union all
    select 'car_1' item_id,null sup_item_id from dual union all
    select 'car_2' item_id,null sup_item_id from dual
    )
    select item_id from data where sup_item_id is null
    start with item_id = 'rim_1' connect by item_id = prior sup_item_id;
    

    Thank you
    Andy

  • Loop of auto repair. Computer will NOT start at the top.

    My HP Pavilion becomes a blue screen with "Unhandled Exception in thread system.  He then brings me to a window of auto repair.  If I click, 'Restoration', the screen turns black with the logo 'HP' and then gets stuck.  If I click 'Cancel', it brings me to a screen that says: "auto repair couldn't fix your PC.  "Log file: C:\Windows\System32\Logfiles\Srt\SrtTrail.txt.

    I tried to go to advanced options and get the command prompt, using:

    Bootrec /fixMBR
    Bootrec /Fixboot
    Bootrec /rebuildBCD

    I also tried to open safe mode.  All with no luck.

    Something else I could try?

    Thank you!

    Hello

    Try to run the automatic repair of a Windows boot disk that often works better
    as the recovery of the system.

    How to run a repair 'automatic' to solve the problems of Windows 8 start
    http://www.eightforums.com/tutorials/2843-automatic-repair-run-Windows-8-a.html

    ======================================================

    If necessary:

    How to start on the "System Recovery Options" in Windows 8
    http://www.eightforums.com/tutorials/2269-system-recovery-options-boot-Windows-8-a.html

    Try to do a "Refresh your PC without affecting your files" (or modification of your personal data
    settings) or even a restore.

    Windows 8 includes special discount methods (keep files and settings) or a reset
    (new installation remove all).

    How to restore, refresh or reset your PC
    http://Windows.Microsoft.com/en-us/Windows-8/restore-refresh-reset-PC

    How to create a system image to refresh your PC in Windows 8
    http://support.Microsoft.com/kb/2748351

    How to update Windows 8
    http://www.eightforums.com/tutorials/2293-refresh-Windows-8-a.html

    How to reset Windows 8
    http://www.eightforums.com/tutorials/2302-reset-Windows-8-a.html

    If you need a repair disc :

    Create a system repair disc
    http://Windows.Microsoft.com/en-us/Windows7/create-a-system-repair-disc

    How to create a "system repair disc" (CD/DVD) in Windows 8
    http://www.eightforums.com/tutorials/2855-system-repair-disc-create-Windows-8-a.html

    =======================================================

    In 'some' case will help this article.

    Crashes Windows or freezes
    http://support.Microsoft.com/kb/2681286

    Do not forget to check with support of system manufacturer (manufacturer of motherboard for custom
    online systems), their resources and the drivers and ask in their forums (if any)
    on known problems. Don't forget to update BIOS, drivers of low level chipset,
    and the other pilots of major on-board and separate devices
    . Those who alone can
    set all or part of these issues.

    Note the use of Win Key + X and Win Key + W (to go on the Control Panel, Run and parameters
    According to needs). Win + D key calls the office and using Win Key active / disable the Office
    and the splash screen.

    Translate Windows 7 methods and use them on Windows 8/8.1

    Resolution of the blue screen in Windows 8/8.1 errors
    http://Windows.Microsoft.com/en-CA/Windows-8/resolve-Windows-blue-screen-errors

    Resolve errors stop (blue screen) in Windows 7 - has a section for if you can or can not
    Start Windows (applies to Windows 8/8.1). If you cannot start Windows 8/8.1 try using
    a disk repair (see methods of doing a below) to access Mode without failure and other evil -.
    steps of shooting.
    http://Windows.Microsoft.com/en-us/Windows7/resolving-stop-blue-screen-errors-in-Windows-7

    Check this thread for more information using BlueScreenView, MyEventViewer and other troubleshooting methods BlueScreens - top 3 responses (+ 1 other) (applies to Windows 8/8.1).

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-system/sometimes-i-get-a-blue-screen-when-using-IE-8/c675b7b8-795f-474d-a1c4-6b77b3fcd990

    We can analyze the minidumps if make you it available the OneDrive or other file sharing sites (such as MediaFire). If you have problems downloading the minidumps copy them on the desktop or the Documents folder and download them from there.

    Adding files to your OneDrive
    http://Windows.Microsoft.com/en-us/Windows-8/getting-started-onedrive-tutorial

    Download pictures and files
    http://Windows.Microsoft.com/en-us/onedrive/add-photos-files A disk - sharing files and folders and change the permissions
    http://Windows.Microsoft.com/en-us/onedrive/share-file-folder

    ZIP or download the content of the C:\Windows\minidump

    Use OneDrive to upload collected files

    http://social.technet.Microsoft.com/forums/en-us/w7itproui/thread/4fc10639-02dB-4665-993a-08d865088d65

    -------------------------------------------------------------------------

    Also this, so you can see the probable bluescreens.

    Windows Vista restarts automatically if your computer encounters an error that requires him to plant. (also, Windows 7 and Windows 8/8.1)
    http://www.winvistatips.com/disable-automatic-restart-T84.html

    ======================================================

    The system has RAID? If so, it's also very suspicious.

    This error is usually a driver problem and adapter (video) display driver is the most suspicious that there could be others. Antivirus/antispyware/security programs, equipment (heat) and major software issues can also cause the error. When you get to the section of the driver of the utility troubleshooting use my generic methods below, and then return to the if necessary troubleshooting tool.

    Have you recently added hardware or drivers updated? Don't forget to look in Control Panel - updates of Windows to see if all drivers have been updated it. Other donor opportunities include security/antivirus/anti-spyware programs.

    ------------------------------------------------------------------

    BCCode: 7F 0x0000007E which is also 0x1000007E

    BCCode: 7F 0x00000007E who is also a 0x1000007E<-- read="" this="">
    * 1141.html? order = votes http://www.faultwire.com/solutions-fatal_error/System-thread-exception-not-HANDLED-0x0000007E-

    Bug Check 0x7E: SYSTEM_THREAD_EXCEPTION_NOT_HANDLED

    http://msdn.Microsoft.com/en-us/library/ff559239 (v = vs. 85) .aspx

    ---------------------------------------------------------------------------------------------

    It's my generic how updates of appropriate driver: (updating the video/display driver and BIOS)

    This utility, it is easy see which versions are loaded: run DriverView - VIEW driver Microsoft set hide - update those without drain in their names (and BIOS and chipset).

    -Free - DriverView utility displays the list of all device drivers currently loaded on your system. For each driver in the list, additional useful information is displayed: load address of the driver, description, version, product name, company that created the driver and more.
    http://www.NirSoft.NET/utils/DriverView.html

    For drivers, visit manufacturer of emergency system and of the manufacturer of the device that are the most common.

    Control Panel device - graphics card configuration-manager - note the brand and complete model of your graphics driver - double-click - tab - write version information. Now, click the driver update (this can do nothing as MS is far behind the certification of drivers) - then do a right click - Uninstall - REBOOT it will refresh the driver stack.

    Repeat for network - card (NIC), Wifi network, sound, mouse, and keyboard if 3rd party with their own software and drivers and the other main device drivers you have.

    Now go to the website of the manufacturer of system (Dell, HP, Toshiba as examples) (restoration), then site of the manufacturer of the device (Realtek, Intel, Nvidia, ATI, for example) and get their latest versions. (Review of the BIOS, Chipset and software updates on the site of the manufacturer of the system while there).

    Download - SAVE - go to where you put them - right click - RUN AD ADMIN - REBOOT after each installation.

    Always check in the Device Manager - tab drivers version you install actually shows up. This is because some restore drivers before the most recent is installed (particularly that audio drivers) so install a driver - reboot - check that it is installed and repeat if necessary.

    Repeat to the manufacturers - BTW in the DO NOT RUN THEIR SCANNER device - check
    manually by model.

    Look at the sites of the manufacturer for drivers - and the manufacturer of the device manually.
    http://pcsupport.about.com/od/driverssupport/HT/driverdlmfgr.htm

    Windows 8/8.1 - hardware and drivers
    http://Windows.Microsoft.com/en-us/Windows/hardware-drivers-help#hardware-drivers-help=Windows-8

    Windows 8/8.1 - Why Windows is not find my device?
    http://Windows.Microsoft.com/en-us/Windows-8/why-isn ' t-windows-conclusion-device

    Windows 8/8.1 - what happens if a device is not installed correctly
    http://Windows.Microsoft.com/en-us/Windows-8/what-device-isn ' t-installed-correctly

    ========================================================

    Windows 8/8.1 includes special discount methods (keep files and settings) or a reset
    (new installation remove all).

    How to restore, refresh or reset your PC (Windows 8/8.1)
    http://Windows.Microsoft.com/en-us/Windows-8/restore-refresh-reset-PC

    How to update Windows 8 & 8.1
    http://www.eightforums.com/tutorials/2293-refresh-Windows-8-a.html

    How to reset Windows 8 & 8.1
    http://www.eightforums.com/tutorials/2302-reset-Windows-8-a.html

    If you need a USB Flash Drive recovery or other methods:

    How to create a recovery USB in Windows 8 & 8.1

    http://www.eightforums.com/tutorials/5132-recovery-drive-create-USB-flash-drive-Windows-8-a.html

    How to start on the "System Recovery Options" in Windows 8 & 8.1
    http://www.eightforums.com/tutorials/2269-system-recovery-options-boot-Windows-8-a.html

    Boot to the tip "Startup parameters" in Windows 8 & 8.1
    http://www.eightforums.com/tutorials/4924-advanced-startup-settings-boot-Windows-8-a.html

    --------------------------------------------------------------------------------------

    Tests of memory intercept all errors, such as memory do not match (possible even for poles that seem identical) and how faster memory is placed in system behind the slower memory. Also is it better to Exchange also sticks in and out to check for those, even if all the tests of memory do not show a problem.

    To test the RAM here control - run 4 + hours or so.<-- best="">
    www.memtest.org

    For the Windows Memory Diagnostic tool.

    WinKEY + W - type in the search-> memory box - find the top Memory Diagnostics tool
    list - and follow the prompts.

    How to run the diagnostic tool for Windows 7 memory (and 8/8.1) - in Windows 8/8.1 the name is "Windows Memory Diagnostic".
    http://www.SevenForums.com/tutorials/715-memory-diagnostics-tool.html

    ======================================================

    After doing ALL the updates you can and if the problem persists, run DriverVerifier.
    (Remember to use the methods Windows 8/8.1 displayed at the top of the first answer above).

    Driver Verifier can help find some BSOD problems:

    Using Driver Verifier to identify issues with Windows drivers for users advanced
    http://support.Microsoft.com/kb/244617

    How to solve the problems of driver in Windows Vista or 7. (also 8/8.1 and 10)
    http://www.WinVistaClub.com/T79.html

    Using Driver Verifier
    http://msdn.Microsoft.com/en-us/library/ff554113 (v = VS. 85) .aspx

    How to use Windows drivers check Manager to solve problems and identify the Driver questions
    http://www.YouTube.com/watch?v=_VwIDD9xngM

    Driver Verifier
    http://www.techsupportforum.com/2110308-POST3.html

    Using Driver Verifier
    http://www.faultwire.com/solutions/using_driver_verifier.php

    You can disable the driver verifier
    http://support.Microsoft.com/kb/244617

    WINDOWS key + X - RUN - type-> auditor/reset press ENTER to disable

    BlueScreenView lets you know if there is a driver specified in the error message. Also check with MyEventViewer when the blue screen.

    If DriverVerifier creates a minidump upload it and post the link here so we can analyze.

    I hope this helps.
    --------------------------------------------------------------------------------------------
    Rob Brown - Microsoft MVP<- profile="" -="" windows="" experience :="" bicycle="" -="" mark="" twain="" said="" it="">

  • find the highest in equal to the data

    Hello
    I need to find the top tied at the rank of gvien to the sort order for each grade is also given
    could you please help me in the present.
    with t1 as 
    (select 'AB' t1_cd , 'A+' t1_rk from dual union all
    select 'BC','BBB-' from dual union all
    select 'CD','B-' from dual union all
    select 'DE','AA' from dual union all
    select 'EF','BB+' from dual),
     t2 as
     ( select 'AB' t2_cd ,'A+' t2_rk, 1 ordr FROM DUAL union all
       select 'AB' , 'A'  ,1 FROM DUAL UNION ALL
       select 'AE' ,'BBB-',3 from dual union all
       select 'BC' ,'BBB-',4 from dual union all
       select 'CD' ,'B-'  ,5 from dual union all
       select 'DE' ,'AA'  ,2 from dual union all
       select 'EF' ,'BB+' ,6 from dual )
    SELECT * FROM T1,T2
    WHERE t1.t1_cd= t2.t2_cd   -- I need to find the  code and rank which have rank greater than equal to BBB-   
    Here, in the above query, I need to find records that have classifications > = 'BBB-' sort order is alos in the ordr T2 table column

    Output expected
    T1_CD     T1_RK     ORDR                            final_Rk
    
    AB     A+     1  < BBB- i.e;4 so output  L
    AB     A+     1  < BBB- i.e;4 so output  L
    BC     BBB-     4  = BBB- i.e;4 so output  E
    CD     B-     5  > BBB- i.e;4 so output  H
    DE     AA     2  < BBB- i.e;4 so output  L
    EF     BB+     6  > BBB- i.e;4 so output  H
    Thank you

    Published by: Smile on May 8, 2012 07:36
    with t1 as
    (select 'AB' t1_cd , 'A+' t1_rk from dual union all
    select 'BC','BBB-' from dual union all
    select 'CD','B-' from dual union all
    select 'DE','AA' from dual union all
    select 'EF','BB+' from dual),
     t2 as
     ( select 'AB' t2_cd ,'A+' t2_rk, 1 ordr FROM DUAL union all
       select 'AB' , 'A'  ,1 FROM DUAL UNION ALL
       select 'AE' ,'BBB-',3 from dual union all
       select 'BC' ,'BBB-',4 from dual union all
       select 'CD' ,'B-'  ,5 from dual union all
       select 'DE' ,'AA'  ,2 from dual union all
       select 'EF' ,'BB+' ,6 from dual )
    SELECT t1.*, t2.*,
                case when t2.ordr > t3.ordr then 'H'
                       when t2.ordr = t3.ordr then 'E'
                       when t2.ordr < t3.ordr then 'L'
                end code
    FROM T1,T2, (select max(ordr) ordr from t2 where t2_rk = 'BBB-') t3
    WHERE t1.t1_cd= t2.t2_cd;
    
    T1_CD T1_RK T2_CD T2_RK       ORDR CODE
    ----- ----- ----- ----- ---------- ----
    AB    A+    AB    A+             1 L
    AB    A+    AB    A              1 L
    BC    BBB-  BC    BBB-           4 E
    CD    B-    CD    B-             5 H
    DE    AA    DE    AA             2 L
    EF    BB+   EF    BB+            6 H   
    
    6 rows selected.
    

Maybe you are looking for