Trouble constructing query...

The following is my data...
Oracle: 10/2G
WITH xTable AS (
                SELECT 2010 AS YEAR, 1 AS SEQ, 'JOHN'  AS NAME, 1110 AS ID fROM DUAL UNION ALL
                SELECT 2010 AS YEAR, 2 AS SEQ, 'JOHN'  AS NAME, 1110 AS ID FROM DUAL UNION ALL
                SELECT 2010 AS YEAR, 1 AS SEQ, 'BOB'   AS NAME, 1112 AS ID FROM DUAL UNION ALL
                SELECT 2010 AS YEAR, 1 AS SEQ, 'TERRY' AS NAME, 1114 AS ID FROM DUAL UNION ALL
                SELECT 2010 AS YEAR, 1  AS SEQ, 'CARL'  AS NAME, 1115 AS ID  FROM DUAL UNION ALL
                SELECT 2010 AS YEAR, 2  AS SEQ, 'CARL'   AS NAME, 1115 AS ID FROM DUAL UNION ALL
                SELECT 2010 AS YEAR, 3  AS SEQ, 'CARL' AS NAME, 1115 AS ID FROM DUAL UNION ALL
                SELECT 2009 AS YEAR, 1 AS SEQ, 'JOHN'  AS NAME, 1110 AS ID FROM DUAL UNION ALL
                SELECT 2009 AS YEAR, 1 AS SEQ, 'BOB'   AS NAME, 1112 AS ID FROM DUAL UNION ALL
                SELECT 2009 AS YEAR, 2 AS SEQ, 'BOB' AS NAME, 1112 AS ID FROM DUAL
SELECT YEAR,SEQ,NAME,ID, count(seq) over (partition by name, year) as seq_cnt
FROM   xTable
ORDER BY YEAR, NAMECurrent Output:
        YEAR     SEQ     NAME     ID     SEQ_CNT
1     2009     1     BOB     1112     2
2     2009     2     BOB     1112     2
3     2009     1     JOHN     1110     1
4     2010     1     BOB     1112     1
5     2010     1     CARL     1115     3
6     2010     3     CARL     1115     3
7     2010     2     CARL     1115     3
8     2010     1     JOHN     1110     2
9     2010     2     JOHN     1110     2
10     2010     1     TERRY     1114     1What i'm trying to do is to only pull back the max sequence(seq) for id's where there is more than one record for a specific year. So, I would like the output to be as following...
Desired Output:
        YEAR     SEQ     NAME     ID     
     2009     2     BOB     1112     
     2009     1     JOHN     1110     
     2010     1     BOB     1112     
     2010     3     CARL     1115     
     2010     2     JOHN     1110     
     2010     1     TERRY     1114      I'm not entirely sure how to go about this, so, any help would be appreciated.

you can try:
SELECT   YEAR, seq, NAME, ID
    FROM (SELECT a.*,
                 ROW_NUMBER() OVER(PARTITION BY YEAR, NAME ORDER BY seq DESC)
                                                                             rn
            FROM xtable a)
   WHERE rn = 1
ORDER BY YEAR, NAME;

Similar Messages

  • Trouble writing Query for Pivoting data from a table

    I am having a little trouble writing a query for converting the below table data into a pivot data. I am trying to write a query for which if I give a single valid report_week date as input it should give me the data for that week and also provide two extra columns, one which gives the data of last week for the same countries and the second column which gives the difference of numbers in both the columns(i.e. COUNT - COUNT_LAST_WEEK).
    REPORT_WEEK     DIVISION     COUNT
    9/26/2009     country1     81
    9/26/2009     country2     97
    9/26/2009     country3     12
    9/26/2009     country4     26
    9/26/2009     country5     101
    10/3/2009     country1     85
    10/3/2009     country2     98
    10/3/2009     country3     10
    10/3/2009     country4     24
    10/3/2009     country5     101
    10/10/2009     country1     84
    10/10/2009     country2     98
    10/10/2009     country3     10
    10/10/2009     country4     25
    10/10/2009     country5     102
    For example, if I give input as 10/10/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/10/2009     country1     84     85     -1
    10/10/2009     country2     98     98     0
    10/10/2009     country3     10     10     0
    10/10/2009     country4     25     24     1
    10/10/2009     country5     102     101     1
    For example, if I give input as 10/3/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/3/2009     country1     85     81     4
    10/3/2009     country2     98     97     1
    10/3/2009     country3     10     12     -2
    10/3/2009     country4     24     26     -2
    10/3/2009     country5     101     101     0
    Can anyone please shed some light on Query building for the above scenarios.
    Thank you
    SKP
    Edited by: user11343284 on Oct 10, 2009 7:53 AM
    Edited by: user11343284 on Oct 10, 2009 8:28 AM

    I assume there is no gap in report weeks. If so:
    SQL> variable report_week varchar2(10)
    SQL> exec :report_week := '10/10/2009'
    PL/SQL procedure successfully completed.
    with t as (
               select to_date('9/26/2009','mm/dd/yyyy') report_week,'country1' division,81 cnt from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country2',97 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country3',12 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country4',26 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country1',85 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country4',24 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country1',84 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country4',25 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country5',102 from dual
    select  max(report_week) report_week,
            division,
            max(cnt) keep(dense_rank last order by report_week) cnt_this_week,
            max(cnt) keep(dense_rank first order by report_week) cnt_last_week,
            max(cnt) keep(dense_rank last order by report_week) - max(cnt) keep(dense_rank first order by report_week) difference
      from  t
      where report_week in (to_date(:report_week,'mm/dd/yyyy'),to_date(:report_week,'mm/dd/yyyy') - 7)
      group by division
      order by division
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    10-OCT-09 country1            84            85         -1
    10-OCT-09 country2            98            98          0
    10-OCT-09 country3            10            10          0
    10-OCT-09 country4            25            24          1
    10-OCT-09 country5           102           101          1
    SQL> exec :report_week := '10/3/2009'
    PL/SQL procedure successfully completed.
    SQL> /
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    03-OCT-09 country1            85            81          4
    03-OCT-09 country2            98            97          1
    03-OCT-09 country3            10            12         -2
    03-OCT-09 country4            24            26         -2
    03-OCT-09 country5           101           101          0
    SQL> SY.

  • Trouble With Query Between Dates:

    Hello Again,
    The query below is giving some trouble in that the line where 'CURRENT_DATE' is between 'START_DATE' and 'END_DATE.
    The query returns records close to those dates but some missing on the END_DATE. I was wondering if there is 'time at play here? How is only the date component used for the search?
    select * from (
    SELECT TO_CHAR (LEAVE.START_DATE, 'DD-MON-YY') AS Start_Date,
    TO_CHAR (LEAVE.END_DATE, 'DD-MON-YY') AS end_date,
    TO_CHAR (CURRENT_DATE, 'DD-MON-YY')AS CURRENT_DATE,
    LEAVE.NAME as NAME,
    LEAVE.ID as ID,
    LEAVE.DAYS as Days,
    LEAVE.SUPERVISOR as Supervisor,
    LEAVE.LEAVE_TYPE,
    FROM "LEAVE"
    WHERE CURRENT_DATE BETWEEN start_date AND end_date
    Kind Regards,
    Steve Welch

    Hi Steve,
    You should be aware that the Oracle datatype DATE also includes a time component.
    select to_char(current_date,'DD-MON-YYYY HH24:MI:SS') date_and_time from dual;
    DATE_AND_TIME       
    18-AUG-2011 13:29:49 Could it be that you are missing some records because they have a time which falls outside your condition?
    Regards
    Andre

  • Trouble grouping query results

    Hi,
    I have 3 tables (Cars, Colors, and Cars_Colors). Cars_Colors
    is a junction table to list all the possible combinations of cars
    and their colors. Using joins, I produce the following results from
    my query:
    CAR_NUM,COLOR_NUM
    Car1, Color1
    Car1, Color2
    Car2, Color1
    Car3, Color1
    Car4, Color1
    Car4, Color2
    Car4, Color3
    Car5, Color3
    Query works fine, my trouble is getting the results to
    display how I want them to. I would like to display the results in
    a single <table>, with a separate <tr> for each
    distinct car, where that <tr> displays the car in the first
    <td> and displays all of the colors associated with that car
    in a second <td>. The colors should be separated by commas.
    E.g.:
    Car1 | Color1, Color2
    Car2 | Color2
    Car3 | Color1
    Car4 | Color1, Color2, Color3
    Car5 | Color3
    Now, I was able to get it to work by first querying for the
    distinct cars in the Cars_Colors table, then loop through each car
    result and perform a second query on the colors associated with the
    current car. But this surely can't be the most efficient method.
    I'd like to use one query to produce the result set I listed
    at the top... with all Car/Color combinations, then use Coldfusion
    to display the output... without having to run another query every
    time through the loop. I've tried using valuelist() but couldn't
    get it to work correctly. I've also tried <cfoutput query
    group> and <cfloop query>. I've come close with both, just
    can't get the commas working right. I don't know how to keep the
    comma from appearing at the end of the colors, e.g.:
    Car1 | Color1, Color2
    Anyone have a better way? I appreciate any help.
    Thanks!

    <CFQUERY name="myQuery"...>
    SELECT .... from ... where...
    ORDER BY car_num, color_num
    </cfquery>
    <cfoutput
    query="myQuery" group="car_num">
    <!--- concat the colors into a string for display --->
    <cfset tempColors = "" /><cfoutput><cfset
    tempColors = listAppend(tempColors, color_num, ", ")
    /></cfoutput>
    #car# - #ListChangeDelims(tempColors, ", ")#<br />
    </cfoutput>
    HTH,
    CR

  • Trouble with query on Reports

    Hi,
    I am having trouble with a query which results from a join of 4 tables, of which, one table is shortened by grouping it along one column.
    for example
    A join B join C join (D grouped by D.S)
    In MS Access I had used a separate query to represent this and done a join with the remaining tables to generate my report.
    Any one has any idea about how this can be done using just one query, or any way I can store the sub-result elsewhere like in Access.
    Thanks!

    Not usre this is a reports issue, but:
    I think you are trying to select from tables and queries in one.
    IN your SQL statement try
    SELECT data,etc
    FROM
    A,
    B,
    C
    , (select distinct S from D) Q_D
    where
    A join B join C join Q_D
    Note that I don't think you can use sub queries like this in Access

  • How to construct query with null parameters in jpa 2.0

    Hi,
    I am creating a jpa 2.0 application. I have an entity with a large number of fields
    @Entity
    @Table(name="notations")
    public class Notation implements Serializable {
         private static final long serialVersionUID = 1L;
         @Id
         private Integer id;
         @Column(name="action_count")
         private Integer actionCount;
         @Column(name="adaptability_comment")
         private String adaptabilityComment;
         @Column(name="adaptability_score")
         private Integer adaptabilityScore;
         private String comment;
         @Column(name="compatibility_comment")
         private String compatibilityComment;
         @Column(name="compatibility_score")
         private Integer compatibilityScore;
         @Column(name="consistency_comment")
         private String consistencyComment;
         @Column(name="consistency_score")
         private Integer consistencyScore;
         @Column(name="controlpoint_name")
         private String controlpointName;
         @Column(name="device_brand")
         private String deviceBrand;
         @Column(name="device_name")
         private String deviceName;
         @Column(name="error_management_comment")
         private String errorManagementComment;
         @Column(name="error_management_score")
         private Integer errorManagementScore;
         @Column(name="explicit_control_comment")
         private String explicitControlComment;
         @Column(name="explicit_control_score")
         private Integer explicitControlScore;
         @Column(name="functionality_name")
         private String functionalityName;
         @Column(name="guidance_comment")
         private String guidanceComment;
         @Column(name="guidance_score")
         private Integer guidanceScore;
         @Column(name="is_available")
         private Boolean isAvailable;
         private String protocol;
         @Column(name="significance_comment")
         private String significanceComment;
         @Column(name="significance_score")
         private Integer significanceScore;
         @Column(name="tester_name")
         private String testerName;
         @Column(name="use_case_name")
         private String useCaseName;
         @Column(name="workload_comment")
         private String workloadComment;
         @Column(name="workload_score")
         private Integer workloadScore;
            getters, settersI am using a method to update this entity as the user changes different fields. My method takes (almost) all fields, but only one (or few) have values, the others are null.
    public Notation updateNotation(Integer id, Boolean isAvailable, String protocol, String deviceBrand,
                   String deviceName,String testerName, Date ratingDate, String functionalityName,
                   String useCaseName,     String controlPointName, Integer actionCount, String comment,
                   Integer adaptabilityScore, Integer compatibilityScore, Integer consistencyScore,
                   Integer errorManagementScore, Integer explicitControlScore, Integer guidanceScore, Integer significanceScore,
                   Integer workloadScore, String adaptabilityComment, String compatibilityComment,
                   String consistencyComment, String errorManagementComment, String explicitControlComment,
                   String guidanceComment, String significanceComment, String workloadComment) throws PersistenceException{
              String setString = "";
              if(isAvailable != null)
                   setString += "n.isAvailable = '" + isAvailable + "',";
              if(!(protocol==null||protocol.isEmpty()))
                   setString += "n.protocol = '" + protocol + "',";
              if(!(deviceBrand==null||deviceBrand.isEmpty()))
                   setString += "n.deviceBrand = '" + deviceBrand + "',";
              if(!(deviceName==null||deviceName.isEmpty()))
                   setString += "n.deviceName = '" + deviceName + "',";
              if(!(testerName==null||testerName.isEmpty()))
                   setString += "n.testerName = '" + testerName + "',";
              if(!(functionalityName==null||functionalityName.isEmpty()))
                   setString += "n.functionalityName = '" + functionalityName + "',";
              if(!(useCaseName==null||useCaseName.isEmpty()))
                   setString += "n.useCaseName = '" + useCaseName + "',";
              if(!(controlPointName==null||controlPointName.isEmpty()))
                   setString += "n.controlPointName = '" + controlPointName + "',";
              if(actionCount != null)
                   setString += "n.actionCount = '" + actionCount + "',";
              if(!(comment==null||comment.isEmpty()))
                   setString += "n.comment = '" + comment + "',";
              if(adaptabilityScore != null)
                   setString += "n.adaptabilityScore = '" + adaptabilityScore + "',";
              if(compatibilityScore != null)
                   setString += "n.compatibilityScore = '" + compatibilityScore + "',";
              if(consistencyScore != null)
                   setString += "n.consistencyScore = '" + consistencyScore + "',";
              if(errorManagementScore != null)
                   setString += "n.errorManagementScore = '" + errorManagementScore + "',";
              if(explicitControlScore != null)
                   setString += "n.explicitControlScore = '" + explicitControlScore + "',";
              if(guidanceScore != null)
                   setString += "n.guidanceScore = '" + guidanceScore + "',";
              if(significanceScore != null)
                   setString += "n.significanceScore = '" + significanceScore + "',";
              if(workloadScore != null)
                   setString += "n.workloadScore = '" + workloadScore + "',";
              if(!(adaptabilityComment==null||adaptabilityComment.isEmpty()))
                   setString += "n.adaptabilityComment = '" + adaptabilityComment + "',";
              if(!(compatibilityComment==null||compatibilityComment.isEmpty()))
                   setString += "n.compatibilityComment = '" + compatibilityComment + "',";
              if(!(consistencyComment==null||consistencyComment.isEmpty()))
                   setString += "n.consistencyComment = '" + consistencyComment + "',";
              if(!(errorManagementComment==null||errorManagementComment.isEmpty()))
                   setString += "n.errorManagementComment = '" + errorManagementComment + "',";
              if(!(explicitControlComment==null||explicitControlComment.isEmpty()))
                   setString += "n.explicitControlComment = '" + explicitControlComment + "',";
              if(!(guidanceComment==null||guidanceComment.isEmpty()))
                   setString += "n.guidanceComment = '" + guidanceComment + "',";
              if(!(significanceComment==null||significanceComment.isEmpty()))
                   setString += "n.significanceComment = '" + significanceComment + "',";
              if(!(workloadComment==null||workloadComment.isEmpty()))
                   setString += "n.workloadComment = '" + workloadComment + "',";
              if(setString!="") setString = setString.substring(0, setString.length()-1);
              String queryString = "UPDATE Notation n SET " + setString + " WHERE n.id = ?1";
              Query q = em.createQuery(queryString);
              q.setParameter(1, id);
              q.executeUpdate();
              return (Notation) em.createQuery("SELECT n FROM Notation n WHERE n.id = ?1").setParameter(1, id).getResultList().get(0);
         }So my question I think is somewhat obvious. What is a good way to construct my query, so that I am not forced to have such an ugly and laborious code (again, knowing that most of the arguments are null)?
    Thanks in advance
    Edited by: StefanC on Jan 27, 2010 3:01 AM

    That is a good point, I will do the operations directly on the entity. However, that still doesn't save me from having to write all those if statements and having an ugly code.
    Husain.AlKhamis wrote:
    Exactly, this is the concept behind JPA --> you have to write zero SQL queries.It's true that you don't have to write any queries for update and remove, however you still have to write JPQL queries (pretty much like SQL) to selections.

  • User constructed query using dropdowns

    Hi all,
    I am trying to create a sql query using select lists with an application page. My problem is that written as a statement it would say;
    select count (distinct id)
    from requests
    where date_raised between '01 JUN 07' and '30 JUN 07';
    but if try to have a select list passing 'date_raised' or 'date_closed' it still works but if I put another for 'between' and 'not between' it has a problem, for example;
    select count (distinct id)
    from requests
    where :P5_SL_RAISED_CLOSED :P5_SL_BETWEEN :P5_START_DATE and :P5_END_DATE
    and date_closed is null or date_closed >:P5_END_DATE;
    Could someone help me please, I searched the forums and nobody seems to have done this. (Or maybe it's so simple they just didn't post!)
    Thanks,
    Jay

    Hi Jay,
    you can accomplish this in following way:
    change your report type to SQL Query(PL/SQL function body returning SQL Query),
    then in region source try this:
    begin
    return 'select count (distinct id)
    from requests where ' || :P5_SL_RAISED_CLOSED ||' '|| :P5_SL_BETWEEN || ' to_date('''|| :P5_START_DATE ||''',''DD-MM-YYYY'') AND to_date(''' || :P5_END_DATE || ''',''DD-MM-YYYY'') and date_closed is null or date_closed > to_date('''|| :P5_END_DATE || ''',''DD-MM-YYY'')';
    end;
    Of course, you should change DD-MM-YYYY to date format used in your fields.
    Hope this helps.
    Tomasz K>

  • Having trouble wrapping query as subquery in order to sum a column

    I have a query whose first column in the "select" is something like "count(distinct t.id)", and the query has a "group by" for several columns.
    This generates a number of rows with a number in the first column representing the number of distinct id values in the resulting group, and several other columns.
    I need to create a modified query that produces the sum of that first column.
    I figured this would look something like:
    select sum(total) from (select count(distinct t.id) as "total", ... from ... ... where)
    I'm not able to get this to work. It appears I can't refer to the alias from the parent query, but I've tried other ways of referencing that column value, and I just can't figure it out.
    I'd prefer not to have to provide the original query here. I'm hoping that I've provided enough information that someone could use to give me a useful response.

    sb92075 wrote:
    How do I ask a question on the forums?
    SQL and PL/SQL FAQ
    Handle:     david.karr
    Status Level:     Pro (560)
    Registered:     Mar 14, 2003
    Total Posts:     911
    Total Questions:     67 (50 unresolved)
    I extend my condolences to you since you rarely get answers to your questions here.What would be the point of asking easy questions? :)

  • Having trouble with query

    I am trying to query for a report to list aircraft by manufacturer, model name, aircraft number, destinations flown, miler per charter and the total revenue per charter, as well as total amount of revenue generated and total number of mile flown for each aircraft. This is what I have so far, I keep getting stumped when I try to sum I get error that certain lines is not single-group group function.
    -----DATA
    3 tables:
    Aircraft {PK} ac_number
    {FK} mod_code
    ac_ttaf
    ac_ttel
    ac_tter
    Model {PK} mod_code
    mod_manufacturer
    mod_name
    mod_seats
    mod_chg_mile
    Charter {PK} char_trip
    char_date
    {FK2} ac_number
    char_destination
    char_hours_flown
    char_hours_wait
    char_fuel_gallons
    char_oil_qts
    FK1} cus_code
    ---code written so far--
    --program Unit 5 Q4 Reprot of Aircraft By Renvue                         
    --author Barbara Forget                                                  
    --date February 24.2008                                                  
    --purpose to list aircraft by revenue, model, manufacturer and number    
    SELECT m.mod_manufacturer "MANUFACTURER",
    m.mod_name "A/C NAME",
    a.ac_number "A/C #",
    c.destination "AIRPORT",
    c.char_distance "TOTALMILEAGE"
    FROM hartmar.model m,
    hartmar.aircraft a,
    hartmar.charter c
    WHERE m.mod_code = a.mod_code (+)
    AND a.ac_number = c.ac_number (+)
    ORDER BY m.mod_name
    Can someone give me a little input as to how to accomplish this, I get the report as such
    MANUFACTURER A/C NAME A/C # AIR TOTALMILEAGE
    Piper Axtec 1484P BNA 352
    Piper Axtec 1484P STL 508
    Piper Axtec 1484P TYS 644
    Piper Axtec 1484P STL 472
    Piper Axtec 1484P STL 508
    Piper Axtec 1484P TYS 644
    Piper Axtec 1484P BNA 352
    Piper Axtec 1484P STL 472
    Piper Axtec 1484P STL 508
    Cessna Citation Mustang 1234C
    Cessna Citation Sovereign 2345C
    MANUFACTURER A/C NAME A/C # AIR TOTALMILEAGE
    Beechcraft KingAir 2289L GNV 1645
    Beechcraft KingAir 2289L ATL 1023
    Beechcraft KingAir 2289L GNV 1645
    Beechcraft KingAir 2289L GNV 1574
    Beechcraft KingAir 2289L ATL 936
    Beechcraft KingAir 2289L ATL 936
    Beechcraft KingAir 2289L GNV 1574
    Beechcraft KingAir 2289L ATL 1023
    Beechcraft KingAir 2289L GNV 1574
    Beechcraft KingAir 2289L GNV 1574
    Piper Navajo Chieftain 2278V GNV 1574
    MANUFACTURER A/C NAME A/C # AIR TOTALMILEAGE
    Piper Navajo Chieftain 4278Y TYS 644
    Piper Navajo Chieftain 2278V BNA 320
    Piper Navajo Chieftain 4278Y GNV 1574
    Piper Navajo Chieftain 4278Y GNV 1574
    Piper Navajo Chieftain 4278Y STL 472
    Piper Navajo Chieftain 2278V GNV 1574
    Piper Navajo Chieftain 2278V BNA 320
    Piper Navajo Chieftain 4278Y ATL 998
    Piper Navajo Chieftain 4278Y TYS 644
    Piper Navajo Chieftain 2278V MOB 884
    Piper Navajo Chieftain 4278Y TYS 646
    MANUFACTURER A/C NAME A/C # AIR TOTALMILEAGE
    Piper Navajo Chieftain 4278Y ATL 936
    Piper Navajo Chieftain 2278V MQY 312
    Piper Navajo Chieftain 2278V MQY 312
    Piper Navajo Chieftain 4278Y ATL 936
    Piper Navajo Chieftain 4278Y TYS 646
    Piper Navajo Chieftain 2278V MOB 884
    Piper Navajo Chieftain 4278Y ATL 998
    Piper Navajo Chieftain 4278Y STL 472
    Piper Navajo Chieftain 4278Y ATL 998
    Piper Navajo Chieftain 4278Y GNV 1574
    Piper Navajo Chieftain 2278V BNA 320
    MANUFACTURER A/C NAME A/C # AIR TOTALMILEAGE
    Piper Navajo Chieftain 4278Y TYS 644
    Piper Navajo Chieftain 4278Y ATL 936
    Piper Navajo Chieftain 4278Y TYS 646
    47 rows selected.
    but, I need each a/c to be listed once with charter number total miles flown and total revenue generated.
    Any suggestions?

    Here's what I could fathom:
    test@ORA10G>
    test@ORA10G> with model as (
      2    select 1 as mod_code, 'Cessna' as mod_manufacturer, 'Citation Mustang' as mod_name, 0.1 as mod_chg_mile from dual union all
      3    select 2,'Piper',     'Axtec',             0.2 from dual union all
      4    select 3,'Piper',     'Navajo Chieftain',  0.3 from dual union all
      5    select 4,'Beechcraft','KingAir',           0.1 from dual union all
      6    select 5,'Cessna',    'Citation Sovereign',0.5 from dual),
      7  aircraft as (
      8    select '1234C' as ac_number, 1 as mod_code from dual union all
      9    select '1484P', 2 from dual union all
    10    select '2278V', 3 from dual union all
    11    select '2289L', 4 from dual union all
    12    select '2345C', 5 from dual union all
    13    select '4278Y', 3 from dual),
    14  charter as (
    15    select 1 as char_trip, '1234C' as ac_number, null as destination, null as char_distance from dual union all
    16    select 2, '1484P', 'BNA', 10     from dual union all
    17    select 3, '1484P', 'STL', 10     from dual union all
    18    select 4, '1484P', 'STL', 20     from dual union all
    19    select 5, '1484P', 'TYS', 100    from dual union all
    20    select 6, '2278V', 'BNA', 20     from dual union all
    21    select 7, '2278V', 'GNV', 30     from dual union all
    22    select 8, '2278V', 'MOB', 40     from dual union all
    23    select 9, '2278V', 'MQY', 50     from dual union all
    24    select 10, '2289L', 'ATL', 10    from dual union all
    25    select 11, '2289L', 'ATL', 20    from dual union all
    26    select 12, '2289L', 'GNV', 15    from dual union all
    27    select 13, '2289L', 'GNV', 25    from dual union all
    28    select 14, '2345C',  null, null  from dual union all
    29 select 15, '4278Y', 'ATL', 10 from dual union all
    30 select 16, '4278Y', 'ATL', 25 from dual union all
    31    select 17, '4278Y', 'GNV', 35    from dual union all
    32    select 18, '4278Y', 'STL', 20    from dual union all
    33    select 19, '4278Y', 'TYS', 40    from dual union all
    34    select 20, '4278Y', 'TYS', 50    from dual)
    35  --
    36  SELECT
    37    m.mod_manufacturer as manufacturer,
    38    m.mod_name as ac_name,
    39    a.ac_number as ac_num,
    40    c.destination as airport,
    41    sum(c.char_distance) as total_mileage,
    42    to_char(sum(c.char_distance*m.mod_chg_mile*0.035),'$99,990.99') as trip_charge
    43  FROM
    44    model m,
    45    aircraft a,
    46    charter c
    47  WHERE m.mod_code = a.mod_code(+)
    48  AND a.ac_number = c.ac_number(+)
    49  GROUP BY m.mod_manufacturer,
    50           m.mod_name,
    51           a.ac_number,
    52           c.destination;
    MANUFACTUR AC_NAME            AC_NU AIR TOTAL_MILEAGE TRIP_CHARGE
    Piper      Axtec              1484P BNA            10       $0.07
    Piper      Navajo Chieftain   2278V BNA            20       $0.21
    Piper      Navajo Chieftain   2278V MQY            50       $0.53
    Piper      Navajo Chieftain   4278Y TYS            90       $0.95
    Piper      Navajo Chieftain   4278Y GNV            35       $0.37
    Cessna     Citation Mustang   1234C
    Piper      Navajo Chieftain   2278V MOB            40       $0.42
    Piper      Axtec              1484P STL            30       $0.21
    Piper      Axtec              1484P TYS           100       $0.70
    Piper      Navajo Chieftain   4278Y STL            20       $0.21
    Piper      Navajo Chieftain   2278V GNV            30       $0.32
    Beechcraft KingAir            2289L ATL            30       $0.11
    Cessna     Citation Sovereign 2345C
    Beechcraft KingAir            2289L GNV            40       $0.14
    Piper Navajo Chieftain 4278Y ATL 35 $0.37
    15 rows selected.
    test@ORA10G>
    test@ORA10G>Notes:
    (1) Lines 29 and 30 (in bold) show that '4278Y', which corresponds to mod_code = 3 i.e. "Piper Navajo Chieftain", flew to ATL twice traveling 10 and 20 miles respectively.
    (2) The last line of the resultset (in bold) shows the total miles for "Piper Navajo Chieftain" i.e. 35 miles.
    The trip charge, consequently, is 35 miles * 0.3 * 0.035 = 0.3675
    where 0.3 is the mod_chg_mile for "Piper Navajo Chieftain".
    (3) Note the change in the columns that constitute the GROUP BY clause. What it does is - for every combination of:
        (i)    m.mod_manufacturer
        (ii)   m.mod_name
        (iii)  a.ac_number
        (iv)   c.destinationit sums up the c.char_distance and multiplies it with the product of m.mod_chg_mile and 0.035.
    (4) Also note that you can use aggregate functions (sum, in this case) more than once in the SELECT <column_list> part of the query. You need to include the rest of the columns (the 4 above) in the GROUP BY clause.
    Hope that helps.
    cheers,
    pratz

  • Trouble with query and parse in nstrument i/o assistant

    I am setting up instrument i/o assistant to communicate with a simple serial instrument.  Labview is communicating effectively with my instrument (instrument responds to on/off commands sent by labview) but am not reading data from the instrument.
    Here is the problem:
    I send a command "=RV" followed by carraige return.
    The instrument should be sending back two lines of information:
    "=RV
    V=n.n-mm"
    where n and m are numbers, giving me a vacuum pressure.
    When I run "Query and Parse" I get back:
    "=RVc"
    But, the information I really need is in the second line, and is missing for some reason.  Is there some reason I am not reading the full string of information from the instrument, and how can I change it to get the data I need???
    Thanks to anyone who can help.

    In the Instrument I/O Assistant's query and parse step, set your termination character to none. Your instrument is sending a CR, LF, or both and with a termination character enabled, the read will terminate as soon as that character is read. Therefore, you only get the first line of data.

  • Trouble in  query designer?

    Hi experts:
           I want to do a demo about Financial,the requested report need a table just like this:
    *********************|AMOUT |  EXPENSE | RETAINED PROFITS     
    CURRENT YEAR |*********|*************|************************
    LAST YEAR *****|********|*************|*************************
    The year is dynamic,means user can choose a year he want ,then the value of last year where come out.
    thanks a lot!!!!

    hi Zegion,
    you can do it in Query Designer, check answer in your other posting
    How to get a dynamic dimension ?
    hope this helps.

  • Trouble with query

    hi all,
    I had DEPT and EMP tables.
    Each Department contains more than 2 Employees.
    now i need a query to retrieve EMPID in the first row of each Department
    thanks in advance
    rampa

    And have you coded anything yet for this homework assignment?
    HINT: search for 'pivot table' or 'crosstab query'

  • Trouble understanding query results

    select SMS_R_System.Name from SMS_R_System order by SMS_R_System.Name
    The query produces simple results as expected:
    Name
    LABS-W7-TEST1 
    LABS-WXP-TEST1 
    LSDWD-SCMAPP1 
    LSDWD-UWSWS1 
    LSDWD-UWSWS2 
    But adding an additional item to the query starts producing unexpected duplicates:
    select SMS_R_System.Name, SMS_G_System_PROCESSOR.NumberOfLogicalProcessors from  SMS_R_System inner join SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceId = SMS_R_System.ResourceId order by SMS_R_System.Name
    Why does this query produce a couple of duplicated results?
    Name                   Processor.Number of Logical Processors
    LABS-W7-TEST1   1 
    LABS-WXP-TEST1 1 
    LSDWD-SCMAPP1 2 
    LSDWD-UWSWS1 1 
    LSDWD-UWSWS1 1 
    LSDWD-UWSWS2 1 
    LSDWD-UWSWS2 1 
    The more items I add to the query, the more duplication. Even checking the Omit duplicate rows (select distinct) doesn't solve the problem:
    select distinct SMS_R_System.Name, SMS_G_System_SYSTEM.SMSID, SMS_G_System_PROCESSOR.NumberOfLogicalProcessors, SMS_G_System_X86_PC_MEMORY.TotalPhysicalMemory, SMS_G_System_LOGICAL_DISK.Size from SMS_R_System inner join SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_X86_PC_MEMORY on SMS_G_System_X86_PC_MEMORY.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_LOGICAL_DISK on SMS_G_System_LOGICAL_DISK.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId order by SMS_R_System.Name
    Name                  Configuration Manager GUID                                  
    ProcMemory      Logical Disk
    LABS-W7-TEST1   GUID:772F69EE-7882-4663-B31E-17378D13C159   1   3071544     51097  
    LABS-W7-TEST1   GUID:772F69EE-7882-4663-B31E-17378D13C159   1   3071544    
    LABS-WXP-TEST1  GUID:D50AC145-C365-4BC0-AB20-019015BCB883   1   1023472     51191  
    LABS-WXP-TEST1  GUID:D50AC145-C365-4BC0-AB20-019015BCB883   1   1023472    
    LSDWD-SCMAPP1   GUID:EEA484BD-4A9A-4DC2-B1DA-D61E41B2B5E7   2   12582388    102046 
    LSDWD-SCMAPP1   GUID:EEA484BD-4A9A-4DC2-B1DA-D61E41B2B5E7   2   12582388       
    LSDWD-UWSWS1    GUID:919F425D-1B39-4095-A668-80674D01939D   1   3145272     81816  
    LSDWD-UWSWS1    GUID:919F425D-1B39-4095-A668-80674D01939D   1   3145272    
    LSDWD-UWSWS2    GUID:CEAC8150-7BCC-4C93-8E7B-2CA6DF46B6BF   1   2096616     102398 
    LSDWD-UWSWS2    GUID:CEAC8150-7BCC-4C93-8E7B-2CA6DF46B6BF   1   2096616    
    What is the key to getting the latest record if multiple rows of the same information is stored in the database?

    Multiple rows will show for the same device if it has multiple CPUs (not to confuse with cores)...
    If a device has 2 physical CPUs, then 2 rows will exist in v_GS_PROCESSOR (TSQL equivalent): DeviceID0 = CPU0 & CPU1. Each CPU has x cores as per the field "NumberOfLogicalProcessors0".
    E.g. select top(100) DeviceID0, SocketDesignation0, NumberOfLogicalProcessors0, SystemName0 from v_GS_PROCESSOR order by systemname0 asc
    If you want to know how many logical processors (cores) and you were using TSQL, then you could use a inner join to only show systems that have cores (not null) and use "sum" to add them up in case of multiple rows. A "left" join would
    also show systems that have a null value for NumberOfLogicalProcessors0.
    You cannot use "sum" in WQL...
    select
    SYS.Name0,sum(CPU.NumberOfLogicalProcessors0) As 'NumProcessors'
    from v_R_System As SYS
    inner join v_GS_PROCESSOR As CPU on CPU.ResourceId = SYS.ResourceId
    group by SYS.Name0, CPU.NumberOfLogicalProcessors0
    order by SYS.Name0 Asc
    E.g. results
    LABS-W7-TEST1   1 
    LABS-WXP-TEST1 1 
    LSDWD-SCMAPP1 2 
    LSDWD-UWSWS1 2
    LSDWD-UWSWS2 2
    To get only one row (one CPU), you can use "GROUP BY".
    e.g.
    SELECT
    SMS_R_System.Name, SMS_G_System_PROCESSOR.NumberOfLogicalProcessors
    FROM
    SMS_R_System
    inner join SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceId = SMS_R_System.ResourceId
    GROUP BY SMS_R_System.Name, SMS_G_System_PROCESSOR.NumberOfLogicalProcessors
    ORDER BY SMS_R_System.Name

  • About query Operator in find page??

    hi all~
    I hava a trouble about query operator.
    for example:
    In find page , there are some attribute for query.
    attribute BRAND for query the vender's name,
    Assume database has the follow data:
      BRAND
    =================
    1.IBM
    2.RedIBM
    3.BLUEIBMCO
    Case 1:When i input IBM in BRAND attribute and press Find,the result is :IBM
    Case 2:When i input %IBM in BRAND attribute and press Find,the result is : RedIBM,BLUEIBMCO
    How could I get above two result just input IBM??
    I want to serch the value of BRAND that contain IBM whether it location at the frond or middle.

    Spray Lin,
    I'm afraid that this time I do not quite understand what you are after.
    When I understand you correctly, you are saying that the current behavior is not what I think it should be, for example IBM results in IBM and IBMblue. That is strange indeed.
    Furthermore is it that when you try to find on IBM it should find everything with IBM in it? Said in other words, entering IBM should have the same result as entering %IBM%?
    If that is the case, you can achieve that by adding an extra property to the find form bean: "wildcardUsage". Setting this to "surround" will result in a "%" being put in front and at the end of the value you enter.
    You can look this up in the JHeadstart Developers Guide in the section Model-Aware Form Beans.
    Jan Kettenis,
    JHeadstart Team

  • Using query strings in links mysite.verizon web pages

    Has anyone had trouble using query strings in links to other web pages your personal web pages?  I have a link to another web page where I pass an ID using query string but when I click on the link I get a 404 error even though the web page exists (the link appears fine).

    Hello jillibee,
    Maybe this link will provide some assistance for you. http://forums.verizon.com/t5/FiOS-Internet/Personal-Website-Access/m-p/277209/highlight/true#M19266
    Thanks,
    Shamika_Vz
    Verizon Support
    Notice: Content posted by Verizon employees is meant to be informational and does not supersede or change the Verizon Forums User Guidelines or Terms or Service, or your Customer Agreement Terms and Conditions or Plan.

Maybe you are looking for

  • Ipod touch 4th gen cannot be detected by softwares (including itunes)

    Hi i bought an ipod touch for about 9 months now and encounter no problem but until recently when i plug my ipod on to my computer, the computer recognises it and a pop out appear for the auto play menu but,when i open itunes or any other 3rd party s

  • InstantiationException when trying to reference an external jar in my web service sample

    Dear all, I'm working with Weblogic 6.1 SP3 (on NT platform) and, starting from weather weblogic web service sample, I'm trying to build my first web service sample. I developed a simple EJB (called OrderManager) that exposes the following functional

  • PO for transport and connection with price of the materials

    Hi all, I have a little problem here and I would appreciate any kind of help and advice! If I make one PO for goods to one vendor, and differend PO for transport of goods to differend vendor how can I link this second PO with the first in order to in

  • Installing Tiger

    Just bought a new MacMini and 20" cinema display. Its great! Opening those boxes got my grinning like a kid with a new toy. Anyway, I tried installing Tiger with the CD supplied with the MacMini on my iBook G4. Didn't work. Clicked restart on the OSX

  • Ni-daq 4.9.4 error on a mac

    Hi all, I have just finished assembling a really old Mac Quadra 840AV and installed a nb-mio-16L card. After several attempts I still cannot get any daq vi to read from the card. I am running Labview 4 with about 250MB on hard disk. The error I get i