NEED HELP WITH QUERY, NEED NEWEST RECORD ONLY

Hi all,
Here goes,
I have an assingment in which i need to find the agents who allow the footballers to break the rules.
So far i have 41 results, in which there is 4 agents and 24 footballers, and the same footballer has broken more than one rule or the rule more than once.
What i now need is to arrange so that each footballer on shows up once no matter how many times they have broken the rules.
i have
SELECT
t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
FROM
agents a, transfers t, footballers f, footballers_fees fo
WHERE
a.agent_id = t.broker_id
AND
t.footballer_id = f.footballer_id
AND
f.footballer_id = fo.footballer_id
AND
(RULE 1 BROKEN AND RULE 2 BROKEN
OR
RULE 1 BROKEN AND RULE 2 NOT BROKEN
OR
RULE 1 NOT BROKEN AND RULE 2 BROKEN)
GROUP BY
t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
ORDER BY
t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
(I havent typed out the SQL for the rules 1 and 2 but i know it works)
Now i need to show only each footballer once whether they have broken either rule and more than once or not.
I have been staring at the screen for near enough 10 hours and any help or ideas would be greatly appreciated
Thanks all :)

884080 wrote:
Hi all,
Here goes,
I have an assingment in which i need to find the agents who allow the footballers to break the rules.
So far i have 41 results, in which there is 4 agents and 24 footballers, and the same footballer has broken more than one rule or the rule more than once.
What i now need is to arrange so that each footballer on shows up once no matter how many times they have broken the rules.
i have
SELECT
t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
FROM
agents a, transfers t, footballers f, footballers_fees fo
WHERE
a.agent_id = t.broker_id
AND
t.footballer_id = f.footballer_id
AND
f.footballer_id = fo.footballer_id
AND
(RULE 1 BROKEN AND RULE 2 BROKEN
OR
RULE 1 BROKEN AND RULE 2 NOT BROKEN
OR
RULE 1 NOT BROKEN AND RULE 2 BROKEN)
GROUP BY
t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
ORDER BY
t.transfer_time || ' ' || a.first_name || ' ' || a.last_name || ' ' || f.first_name || ' ' || f.last_name || ' ' || f.footballer_id || ' ' || t.transfer_id
(I havent typed out the SQL for the rules 1 and 2 but i know it works)
Now i need to show only each footballer once whether they have broken either rule and more than once or not.
I have been staring at the screen for near enough 10 hours and any help or ideas would be greatly appreciated
Thanks all :)Realize that we don't have your tables or data, so we can't run, test, or improve your SQL.
so what exactly do you expect from us?

Similar Messages

  • Help with Audio Playback While Recording

    I am an aspiring sound engineer and I am having a problem with recording in Audition 3.0 that I need help with. When i record vocals, the sound wave plays back in the speakers/headphones with like a 1.5 second delay after it is recorded. It really throws off the artists I am working with when they are trying to record vocals. How do i kill headphone/speaker playback while someone is recording?

    There are problems with a lot of internal soundcards in a lot of laptops, and these seem to be so many and various that all you can do is use trial and error and hope for the best.
    External soundcards should cure any problem, but you may have to look into what else is running on the laptop, as so much is integrated, and some machines seem to have audio problems caused by wireless or other network adaptors etc.
    As I said, I use oldish Edirol and Tascam usb units. The Tascam has a known fault (noise when using a guitar channel at the same time as phantom powering a mic on the other channel) which I can live with, and I would hope has been solved in later and current versions. The Edirol is fine. I use 2 units to give me the connections I want (ie one has jacks, the other phono plugs, and different size headphone sockets). Both these have asio and wdm drivers and work fine with AA 3.0 here. More modern devices will be usb2 and will presumably provide more channels or higher sampling rates, but these are fine. Others will be more up to date than me, but I would think anything from Tascam, Edirol, Echo Audio and I think most m-audio models should be fine. Just be wary of anything from Creative Labs. I, too, have had bad experiences with one of their products (it drew too much current from the usb port on a couple of the laptops so I never got as far as to find whether it had asio drivers working or not). But others will be more up to date than I am.
    I just went onto ebay over the years and kept bidding on sensible looking devices until I got ones at the right price, but it probably is better to buy new if you can afford it.
    Sorry I can't give a more definite answer.

  • Help with query to do with aggregating for MIN(DATE)

    Say i have the following table of data:
    Table: TEST               
    ID     TDATE     CLIENT     VAL
    1A     1/10/2005     client1     10
    2A     2/10/2005     client1     30
    3A     3/11/2005     client2     22
    4A     5/10/2005     client2     43
    5A     5/10/2005     client2     3
    6A     6/10/2005     client3     5
    7A     7/10/2005     client3     76
    I want to create a query that will retrieve a distinct list of the CLIENT column (ie. in the above table I want only 3 records retrieved in the query as there are only 3 clients) and the corresponding ID and VAL for the client record with the MIN(DATE). In the case where 2 dates are the same, I dont care which record is selected as long as the ID and VAL columns belong to the same record.
    For example in the above data I would expect the following returned in the query:
    ID     CLIENT     VAL
    1A     client1     10
    4A     client2     43 <- this record could also be 5A, client2, 3
    6A     client3     5
    Please help.

    Hi Joshua,
    You didn't post your Oracle version but I hope it supports analytic functions.
    Try as follows:
    SQL> select id,
      2         tdate,
      3         client,
      4         val
      5    from (select t.*,
      6                 row_number() over
      7                   (partition by client order by tdate) rn
      8            from test t)
      9   where rn = 1;
    ID         TDATE      CLIENT                                VAL
    1A         01/10/2005 client1                                10
    4A         05/10/2005 client2                                43
    6A         06/10/2005 client3                                 5Regards.

  • Help with query calculations (recursive)

    Hi All,
    I want some help with a query using a base rate and the result use in the next calculation year.
    Here an example:
    create table rate_type(
    rate_type_id    number,
    rate_desc       nvarchar2(50),
    rate_base_year  number
    insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (1, 'Desc1', 4.6590);
    insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (2, 'Desc2', 4.6590);
    create table rates (
    rate_type_id number
    rate_year    number,
    rate_value   number
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2012, 1.2);
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2013, 1.3);
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2014, 1.4);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2012, 1.2);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2013, 1.3);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2014, 1.4);The calculation for the first year should be the base rate of the rate type. The next year should use the result of the previous year and so on.
    The result of my sample data is:
    2012 = 4.659 + 1.2 + 4.659 * (1.2 * 0.01) = 5.9149
    2013 = 5.9149 + 1.3 + 5.9149 * (1.3 * 0.01) = 7.1859
    2014 = 7.1859 + 1.4 + 7.1859 * (1.4 * 0.01) = 8.4721Query result:
    NAME 2012 2013 2014
    Desc1 5.9149 7.1859 8.4721
    Desc2 XXXX XXX XXXX
    How can I do this in one select statement? Any ideas?
    Thanks!

    Assuming you are on 11.2:
    with t as (
               select  a.rate_type_id,
                       rate_desc,
                       rate_year,
                       rate_base_year,
                       rate_value,
                       count(*) over(partition by a.rate_type_id) cnt,
                       row_number() over(partition by a.rate_type_id order by rate_year) rn
                 from  rate_type a,
                       rates b
                 where a.rate_type_id = b.rate_type_id
        r(
          rate_type_id,
          rate_desc,
          rate_year,
          rate_base_year,
          rate_value,
          cnt,
          rn,
          result
         ) as (
                select  rate_type_id,
                        rate_desc,
                        rate_year,
                        rate_base_year,
                        rate_value,
                        cnt,
                        rn,
                        rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
                  from  t
                  where rn = 1
               union all
                select  t.rate_type_id,
                        t.rate_desc,
                        t.rate_year,
                        t.rate_base_year,
                        t.rate_value,
                        t.cnt,
                        t.rn,
                        r.result + t.rate_value + r.result * t.rate_value * 0.01 result
                  from  r,
                        t
                  where t.rate_type_id = r.rate_type_id
                    and t.rn = r.rn + 1
    select  *
      from  (
             select  rate_desc name,
                     rate_year,
                     result
               from  r
               where rn <= cnt
      pivot (sum(result) for rate_year in (2012,2013,2014))
      order by name
    NAME             2012       2013       2014
    Desc1        5.914908  7.2918018 8.79388703
    Desc2        5.914908  7.2918018 8.79388703
    SQL> Obviously pivoting assumes you know rate_year values upfront. If not, then without pivoting:
    with t as (
               select  a.rate_type_id,
                       rate_desc,
                       rate_year,
                       rate_base_year,
                       rate_value,
                       count(*) over(partition by a.rate_type_id) cnt,
                       row_number() over(partition by a.rate_type_id order by rate_year) rn
                 from  rate_type a,
                       rates b
                 where a.rate_type_id = b.rate_type_id
        r(
          rate_type_id,
          rate_desc,
          rate_year,
          rate_base_year,
          rate_value,
          cnt,
          rn,
          result
         ) as (
                select  rate_type_id,
                        rate_desc,
                        rate_year,
                        rate_base_year,
                        rate_value,
                        cnt,
                        rn,
                        rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
                  from  t
                  where rn = 1
               union all
                select  t.rate_type_id,
                        t.rate_desc,
                        t.rate_year,
                        t.rate_base_year,
                        t.rate_value,
                        t.cnt,
                        t.rn,
                        r.result + t.rate_value + r.result * t.rate_value * 0.01 result
                  from  r,
                        t
                  where t.rate_type_id = r.rate_type_id
                    and t.rn = r.rn + 1
    select  rate_desc name,
            rate_year,
            result
      from  r
      where rn <= cnt
      order by name,
               rate_year
    NAME        RATE_YEAR     RESULT
    Desc1            2012   5.914908
    Desc1            2013  7.2918018
    Desc1            2014 8.79388703
    Desc2            2012   5.914908
    Desc2            2013  7.2918018
    Desc2            2014 8.79388703
    6 rows selected.
    SQL> SY.

  • Need help with query joining several tables into a single return line

    what i have:
    tableA:
    puid, task
    id0, task0
    id1, task1
    id2, task2
    tableB:
    puid, seq, state
    id0, 0, foo
    id0, 1, bar
    id0, 2, me
    id1, 0, foo
    id2, 0, foo
    id2, 1, bar
    tableC:
    puid, seq, date
    id0, 0, 12/21
    id0, 1, 12/22
    id0, 2, 12/22
    id1, 0, 12/23
    id2, 0, 12/22
    id2, 1, 12/23
    what i'd like to return:
    id0, task0, 12/21, 12/22, 12/22
    id1, task1, 12/23, N/A, N/A
    id2, task2, 12/22, 12/23, N/A
    N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
    id0, task0, 12/21
    id0, task0, 12/22
    id0, task0, 12/23
    id1, task1, 12/23
    is this possible fairly easily?
    Edited by: user9979830 on Mar 29, 2011 10:53 AM
    Edited by: user9979830 on Mar 29, 2011 10:58 AM

    Hi,
    Welcome to the forum!
    user9979830 wrote:
    what i have:...Thanks for posting that so clearly!
    Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
    CREATE TABLE     tablea
    (       puid     VARCHAR2 (5)
    ,     task     VARCHAR2 (5)
    INSERT INTO tablea (puid, task) VALUES ('id0',  'task0');
    INSERT INTO tablea (puid, task) VALUES ('id1',  'task1');
    INSERT INTO tablea (puid, task) VALUES ('id2',  'task2');
    CREATE TABLE     tablec
    (       puid     VARCHAR2 (5)
    ,     seq     NUMBER (3)
    ,     dt     DATE          -- DATE is not a good column name
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  0,  DATE '2010-12-21');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  1,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  2,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id1',  0,  DATE '2010-12-23');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  0,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  1,  DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
    It doesn't look like tableb plays any role in this problem, so I didn't post it.
    Explain how you get the results from that data. For example, why do you want this row in the results:
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/21/2010 12/22/2010 12/22/2010rather than, say
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
    Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
    WITH     got_r_num     AS
         SELECT     puid
         ,     dt
         ,     ROW_NUMBER () OVER ( PARTITION BY  puid
                                   ORDER BY          seq          -- and/or dt
                           )         AS r_num
         FROM    tablec
    --     WHERE     ...     -- If you need any filtering, put it here
    SELECT       a.puid
    ,       a.task
    ,       MIN (CASE WHEN r.r_num = 1 THEN r.dt END)     AS dt1
    ,       MIN (CASE WHEN r.r_num = 2 THEN r.dt END)     AS dt2
    ,       MIN (CASE WHEN r.r_num = 3 THEN r.dt END)     AS dt3
    ,       MIN (CASE WHEN r.r_num = 4 THEN r.dt END)     AS dt4
    FROM       tablea    a
    JOIN       got_r_num r  ON   a.puid  = r.puid
    GROUP BY  a.puid
    ,            a.task
    ORDER BY  a.puid
    ;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
    This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
    Here's the output I got from the query above:
    PUID  TASK  DT1        DT2        DT3        DT4
    id0   task0 12/21/2010 12/22/2010 12/22/2010
    id1   task1 12/23/2010
    id2   task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
    If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
    If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
    There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
    For various ways to deal with a variable number of pivoted coolumns, see the following thread:
    PL/SQL
    This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
    PL/SQL
    If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one.

  • Need help with query that can look data back please help.

    hi guys i have a table like such
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )and i have a data like such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
    fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
    so im trying to write a query that basically does the following.
    im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
    so the expected outcome should be $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400keep in mind that im not given a year just a period.
    any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
    finally broke down and put together this post
    Edited by: mlov83 on Sep 14, 2011 8:48 PM

    Frank
    wondering if you can help me modify this sql statement that you provided me with .
    table values have been modified a bit.
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
    the current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    Miguel

  • Need help with Query

    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE  FSYR      YTD_AMT
    A123            11          100  
    A456            11          200
    A123            10          50
    A456            10          100I want the output to look like this:
    ACCT_CODE     CURRENT_YEAR(11)       PRIOR_YEAR(10)
    A123               100                              50
    A456               200                              100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!
    Edited by: user5737516 on Jun 29, 2011 6:48 AM
    Edited by: user5737516 on Jun 29, 2011 6:50 AM

    user5737516 wrote:
    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE FSYR YTD_AMT
    A123 11 100
    A456 11 200
    A123 10 50
    A456 10 100
    I want the output to look like this:
    ACCT_CODE CURRENT_YEAR PRIOR_YEAR
    A123 100 50
    A456 200 100
    The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!what is prior year?

  • Query off of Oracle using WinSql - Need help with query

    I am trying to query off of Oracle using program WinSql.
    I have a table(tticpr200110) that has the following sample data:
    ITEM     CODE     T$AMNT
    23500076 ACL     .0049
    23500076 APM     0
    23500076 APO     .0093
    23500076 EXP     .0001
    23500076 RES     .0072
    and what I want it to look like is:
    ITEM     ACL     APM     APO     EXP     RES
    23500076     0.0049     0     0.0093     0.0001     0.0072
    (actually I need the last 2 columns added together to be MATL-but can deal with that down the road).
    Seems simple enough, but I don't know to put into the columns.
    Any help would be GREATLY appreciated as soon as possible would be even better.

    My table - tticpr200110 when it runs I get the following sample data for part number 23500076:
    The first coloumn ITEM is the part number.
    The second column CODE is 1 of 5 different cost codes
    The third column is the cost for that code for that part.
    ITEM CODE AMNT
    23500076 ACL 0.0049
    23500076 APM 0.0000
    23500076 APO 0.0093
    23500076 EXP 0.0001
    23500076 RES 0.0072
    I want to make a query that makes the data look like this:
    ITEM ACL APM APO EXP RES
    23500076 0.0049 0.0000 0.0093 0.0001 0.0072
    (similar to a pivot table in excel or acess)
    I hope this helps better.
    Thanks!

  • Need help with Query to determine Credit Memos and Invoices

    Hi All
    Thanks for all the help here.
    I need a query to determine any credits or invoices issued within a given period.
    OINV and ORIN with UNION ALL?
    Please advise any help.
    Thank you!

    Hi Daniel,
    Please check below Query.
    SELECT T0.[DocNum] as 'Invice No', T0.[DocDate] as 'Invoice Date', T0.[CardName] as 'Invoiced Customer', T3.[DocNum] as 'Credit Memo No', T3.[DocDate] as 'Credit Mamo Date', T3.[CardName] as 'Credit Memo Customer' FROM OINV T0  LEFT JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] LEFT JOIN RIN1 T2 ON T2.[BaseEntry] = T1.[DocEntry] AND T2.[BaseLine] =  T1.[LineNum] LEFT JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry] WHERE T0.[DocDate]  >=[%3]  AND   T0.[DocDate] <=[%4]
    Hope this helps
    Regards::::
    Atul Chakraborty

  • Need help with query from .csv file

    I am trying to import a csv file with only 1 column in it.
    The column will only contain a 9 digit ID number. I want to read
    the file then use the contents to query a table to get the names
    and other information and display it. Here is what I have so far:
    <cffile action="read" file="#form.FiletoUpload#"
    variable="csvfile">
    <cfloop index="index" list="#csvfile#">
    <cfquery name="massimport" datasource="data1">
    SELECT * FROM IDTable
    WHERE CardNumber = ('#csvfile#')
    </cfquery>
    </cfloop>
    <cfoutput>#Name# #ID# #Site#</cfoutput>
    I get no errors but I am not getting any results. Just a
    blank page. Does anyone know how to query directly from a csv
    import? Thanks.

    You need to convert your file to a list somehow. Not sure if
    this is the most efficient way but, you can use the cfhttp tag to
    produce a query. Then your where clause becomes,
    where cardnumber in (#quotedvaluelist(query.column)#)
    and you won't need a loop.

  • Need help with Querying XML - XQuery

    Hey guys, im new to this stuff so  I gained some knowledge from internet but I'm running is some problem that I'll explain below. I have XML like:  
    <?xml version="1.0" encoding="iso-8859-1"?>
    <star:ShowLaborOperations xmlns:star="http://www.starstandard.org/STAR/5" releaseID="5.4.4">
    <star:ApplicationArea>
    <star:Sender>
    <star:CreatorNameCode>AD</star:CreatorNameCode>
    <star:SenderNameCode>DDDD</star:SenderNameCode>
    <star:SystemVersion>AD2.0</star:SystemVersion>
    </star:Sender>
    <star:CreationDateTime>2011-05-06T12:51:33Z</star:CreationDateTime>
    <star:BODID>A29BF24F-F68E-5CE5-E040-35A54242A0C</star:BODID>
    <star:Destination>
    <star:DestinationNameCode>AD</star:DestinationNameCode>
    </star:Destination>
    </star:ApplicationArea>
    <star:ShowLaborOperationsDataArea>
    <star:Show>
    <oagis:ResponseCriteria xmlns:oagis="http://www.openapplications.org/oagis/9">
    <oagis:ChangeStatus>
    <oagis:Description>Changes</oagis:Description>
    </oagis:ChangeStatus>
    </oagis:ResponseCriteria>
    </star:Show>
    <star:LaborOperations>
    <star:LaborOperationsHeader>
    <star:RequestCode>Changes</star:RequestCode>
    <star:LaborOperationsHeaderBase>
    <star:DocumentIdentificationGroup>
    <star:DocumentIdentification>
    <star:DocumentID>ShowOperationCode20110506050532TY</star:DocumentID>
    </star:DocumentIdentification>
    </star:DocumentIdentificationGroup>
    </star:LaborOperationsHeaderBase>
    <star:LaborOperationCodes/>
    </star:LaborOperationsHeader>
    <star:LaborOperationsDetail>
    <star:LaborOperationID>001020</star:LaborOperationID>
    <star:MajorGroupID>00</star:MajorGroupID>
    <star:ComponentGroupID>01</star:ComponentGroupID>
    <star:LaborOperationDescription>GAS TANK FILL</star:LaborOperationDescription>
    <star:LaborActionCode>OTH</star:LaborActionCode>
    <star:LaborOperationsChangeStatus>U</star:LaborOperationsChangeStatus>
    <star:Combinations>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTN</star:VehicleGroupID>
    <star:VehicleID>JJXB0</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>A</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.0</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>false</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTM</star:VehicleGroupID>
    <star:VehicleID>ZF32V</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>U</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.6</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>true</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    </star:Combinations>
    </star:LaborOperationsDetail>
    </star:LaborOperations>
    </star:ShowLaborOperationsDataArea>
    </star:ShowLaborOperations>
    and I wanna be able to see the following result: 
    <LaborOperationsDetail xmlns="http://www.starstandard.org/STAR/5">
    <LaborOperationID>001020</LaborOperationID>
    <MajorGroupID>00</MajorGroupID>
    <ComponentGroupID>01</ComponentGroupID>
    <LaborOperationDescription>GAS TANK FILL</LaborOperationDescription>
    <LaborActionCode>OTH</LaborActionCode>
    <LaborOperationsChangeStatus>U</LaborOperationsChangeStatus>
    <Combinations>
    <VehicleGroupLaborAllowance>
    <VehicleIdentificationGroup>
    <VehicleGroupID>JTN</VehicleGroupID>
    <VehicleID>JJXB0</VehicleID>
    </VehicleIdentificationGroup>
    <ChangeStatus>A</ChangeStatus>
    <LaborAllowanceMeasure unitCode="hour">0.0</LaborAllowanceMeasure>
    <ChargeHoursIndicator>false</ChargeHoursIndicator>
    </VehicleGroupLaborAllowance>
    </Combinations>
    </LaborOperationsDetail>
    for which I'm writing the following query 
    SELECT OpCodeXMLCol.query('
    declare default element namespace "http://www.starstandard.org/STAR/5";
    /ShowLaborOperations/ShowLaborOperationsDataArea/LaborOperations/LaborOperationsDetail[Combinations/VehicleGroupLaborAllowance/VehicleIdentificationGroup/VehicleGroupID="JTN"][LaborOperationID="001020"]
    -- specified [LaborOperationID="001020"] because there are multiple <LabrOperationDetial> ') as x
    FROM XMLData.dbo.OpCodeData
    where [ID] = 3 -- primary key for that row containing XML in first snippet
    but I'm getting both nodes for <VehicleIdentificatonGroup> whereas I expect to see one containing <VehicleGroupID>JTN</VehicleGroupID> as per filter in query. Please help

    The closest thing which makes sense:
    DECLARE @Data XML = N'
    <star:ShowLaborOperations xmlns:star="http://www.starstandard.org/STAR/5" releaseID="5.4.4">
    <star:ApplicationArea>
    <star:Sender>
    <star:CreatorNameCode>AD</star:CreatorNameCode>
    <star:SenderNameCode>DDDD</star:SenderNameCode>
    <star:SystemVersion>AD2.0</star:SystemVersion>
    </star:Sender>
    <star:CreationDateTime>2011-05-06T12:51:33Z</star:CreationDateTime>
    <star:BODID>A29BF24F-F68E-5CE5-E040-35A54242A0C</star:BODID>
    <star:Destination>
    <star:DestinationNameCode>AD</star:DestinationNameCode>
    </star:Destination>
    </star:ApplicationArea>
    <star:ShowLaborOperationsDataArea>
    <star:Show>
    <oagis:ResponseCriteria xmlns:oagis="http://www.openapplications.org/oagis/9">
    <oagis:ChangeStatus>
    <oagis:Description>Changes</oagis:Description>
    </oagis:ChangeStatus>
    </oagis:ResponseCriteria>
    </star:Show>
    <star:LaborOperations>
    <star:LaborOperationsHeader>
    <star:RequestCode>Changes</star:RequestCode>
    <star:LaborOperationsHeaderBase>
    <star:DocumentIdentificationGroup>
    <star:DocumentIdentification>
    <star:DocumentID>ShowOperationCode20110506050532TY</star:DocumentID>
    </star:DocumentIdentification>
    </star:DocumentIdentificationGroup>
    </star:LaborOperationsHeaderBase>
    <star:LaborOperationCodes/>
    </star:LaborOperationsHeader>
    <star:LaborOperationsDetail>
    <star:LaborOperationID>001020</star:LaborOperationID>
    <star:MajorGroupID>00</star:MajorGroupID>
    <star:ComponentGroupID>01</star:ComponentGroupID>
    <star:LaborOperationDescription>GAS TANK FILL</star:LaborOperationDescription>
    <star:LaborActionCode>OTH</star:LaborActionCode>
    <star:LaborOperationsChangeStatus>U</star:LaborOperationsChangeStatus>
    <star:Combinations>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTN</star:VehicleGroupID>
    <star:VehicleID>JJXB0</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>A</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.0</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>false</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    <star:VehicleGroupLaborAllowance>
    <star:VehicleIdentificationGroup>
    <star:VehicleGroupID>JTM</star:VehicleGroupID>
    <star:VehicleID>ZF32V</star:VehicleID>
    </star:VehicleIdentificationGroup>
    <star:ChangeStatus>U</star:ChangeStatus>
    <star:LaborAllowanceMeasure unitCode="hour">0.6</star:LaborAllowanceMeasure>
    <star:ChargeHoursIndicator>true</star:ChargeHoursIndicator>
    </star:VehicleGroupLaborAllowance>
    </star:Combinations>
    </star:LaborOperationsDetail>
    </star:LaborOperations>
    </star:ShowLaborOperationsDataArea>
    </star:ShowLaborOperations>
    WITH XMLNAMESPACES ( DEFAULT 'http://www.starstandard.org/STAR/5' )
    SELECT LaborOperationsDetail.query('.'),
    VehicleGroupLaborAllowance.query('.')
    FROM @Data.nodes('/ShowLaborOperations/ShowLaborOperationsDataArea/LaborOperations/LaborOperationsDetail') A ( LaborOperationsDetail )
    CROSS APPLY LaborOperationsDetail.nodes('Combinations/VehicleGroupLaborAllowance[VehicleIdentificationGroup/VehicleGroupID="JTN"]') B ( VehicleGroupLaborAllowance );
    Otherwise we need to destruct and rebuild the XML. This in this case imho better done with XSLT.

  • Need help with an applet that will only run as an application

    I am working on a slide show applet. The problem is that is won't run as an applet. I added a quite standard main method to stick the applet in a JFrame and this worked. I believe that the problem lies in how I am trying to open the files.
    here are two of the methods that I believe contain part of the problem
         private void showImage( String image_name )
              image_file = Toolkit.getDefaultToolkit().getImage( image_name );
              display_image.loadImage( image_file );
              repaint();
         private void setFileFolder( String folder )
              file_finder = new File( folder );
              file_results = file_finder.list();
         }image_file is an object of class Image, display_image is an object of class ImageComponent (extends JComponent to draw an image), and file_finder and file_results are both objects of class File
    I would greatly appreciate it if some one would help me with this.
    The full source can be found at http://www.geocities.com/enchantedforest/3688/ImSP.zip

    Ok. I got the image loading to work.
    Now how do I fix the second method shown in my first post? It is needed to find all of the images in one specific folder so that the slide show can run.

  • Need help with querying pl/sql collections

    hi all,
    i have a requirement wherein i look thru a number of records and then updates. then i need to check if these records were successfully updated. i have the following code but it doesn't work on the part where i query the collection.
    declare
      type ap_invoices_all_tbl is table of ap_invoices_all%rowtype;
      ap_invoices_all_rec ap_invoices_all_tbl;
      cursor cai is
        select *
          from ap_invoices_all ai
         where source = 'XXX';
    begin
      open cai;
      fetch cai bulk collect into ap_invoices_all_rec;
      for i in 1..ap_invoices_all_rec.count loop
        begin
        dbms_output.put_line('Invoice Status: ' || ap_invoices_pkg.get_approval_status( ap_invoices_all_rec(i).invoice_id, ap_invoices_all_rec(i).invoice_amount, ap_invoices_all_rec(i).payment_status_flag, ap_invoices_all_rec(i).invoice_type_lookup_code));
        exception
          when no_data_found then
            null;
        end;
      end loop;
      for j in ( select * from ap_invoices_all ai
                  where invoice_id in ( select invoice_id
                                          from ap_invoices_all_rec ))
      loop
        dbms_output.put_line('Invoice Number: ' || j.invoice_num);
      end loop;
    end;i do understand that i cannot use select statement directly on a collection but i just wanted to show what i'm trying to achieve.
    any suggestions on what i should do?
    thanks
    allen

    You can not use locally defined collection(pl/sql) in SELECT statement directly, instead use Objects defined in schema.
    For example:
    SQL> CREATE OR REPLACE TYPE emp_rec IS OBJECT (
      2                      v_sal    NUMBER(7,2),
      3                      v_name   VARCHAR2(35),
      4                      v_empno  NUMBER(4),
      5                      v_deptno NUMBER(2)
      6                      )
      7  ;
      8  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tab IS TABLE OF emp_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_rec IS OBJECT (
      2                      v_deptno NUMBER,
      3                      v_dname VARCHAR2(50)
      4                      )
      5  ;
      6  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_tab IS TABLE OF dept_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_rec IS
      2                     OBJECT (
      3                      v_sal     NUMBER,
      4                      v_name     VARCHAR2(35),
      5                      v_deptname VARCHAR2(30)
      6                      );
      7  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
      2  /
    Type created.
    SQL> set serverout on
    SQL> DECLARE
      2    l_emp_dept_tab emp_dept_tab_type; --emp_dept_tab_type declared in database
      3    l_emp_tab      emp_tab; --emp_tab declared in database
      4    l_dept_tab     dept_tab; --dept_tab declared in database
      5 
      6    CURSOR e1 IS
      7      SELECT emp_rec(sal, ename, empno, deptno) FROM emp; --Note the type casting here
      8 
      9    CURSOR d1 IS
    10      SELECT dept_rec(deptno, dname) FROM dept; --Note the type casting here
    11  BEGIN
    12    OPEN e1;
    13 
    14    FETCH e1 BULK COLLECT
    15      INTO l_emp_tab;
    16 
    17    OPEN d1;
    18 
    19    FETCH d1 BULK COLLECT
    20      INTO l_dept_tab;
    21 
    22    SELECT CAST(MULTISET (SELECT em.v_sal, em.v_name, dep.v_dname
    23                   FROM TABLE(l_emp_tab) em, TABLE(l_dept_tab) dep
    24                  WHERE em.v_deptno = dep.v_deptno) AS emp_dept_tab_type)
    25      INTO l_emp_dept_tab
    26      FROM DUAL;
    27    FOR i IN 1 .. l_emp_dept_tab.COUNT LOOP
    28      dbms_output.put_line(l_emp_dept_tab(i)
    29                           .v_sal || '--' || l_emp_dept_tab(i)
    30                           .v_name || '--' || l_emp_dept_tab(i).v_deptname);
    31    END LOOP;
    32 
    33  END;
    34  /
    1300--MILLER--ACCOUNTING
    5000--KING--ACCOUNTING
    2450--CLARK--ACCOUNTING
    3000--FORD--RESEARCH
    1100--ADAMS--RESEARCH
    3000--SCOTT--RESEARCH
    2975--JONES--RESEARCH
    800--SMITH--RESEARCH
    950--JAMES--SALES
    1500--TURNER--SALES
    2850--BLAKE--SALES
    1250--MARTIN--SALES
    1250--WARD--SALES
    1600--ALLEN--SALES
    PL/SQL procedure successfully completed.
    SQL>

  • Need help with multi track/simultaneous recording

    Please forgive me if the answer to my question has already been covered; I have searched the other posts but haven't been able to find the answer.
    I am recording a podcast with a Behringer Xenyx X1832 mixer. In GB I know how to select "multi track recording" and set my two mics that are conneced to the first two channels of the mixer to "mono 1" and "mono 2" on the input source.
    My question is how do I record audio from my Macbook on a seperate track?
    I have a Focusrite 2i2 connected via USB to the Macbook acting as an output, then TRS cables from the outputs going to channel 7/8 on the mixer. When I play audio I can hear it perfect and adjust EQ and volume, but I am unable to record it on a seperate track on GB.
    When I click on the track on GB, the input source says "stereo 1/2" and when I try to click the red buttons to arm the other two mono tracks where my mics are connected it says "The input channel of this track is already in use. To record on this track, choose another input channel."
    What am I doing wrong? How do I send audio from the Macbook to the mixer and then record it on a seperate track, along with seperate tracks for each of the mics?

    You need to create an aggregate device:
    http://support.apple.com/kb/HT1215

  • Need Help With Query Using Aggregation

    If I have a table, defined like this:
    CREATE TABLE range_test
    range_id NUMBER(20) NOT NULL,
    grade CHAR(1) NOT NULL,
    lower_bound_of_range NUMBER(5,2) NOT NULL,
    upper_bound_of_range NUMBER(5,2) NOT NULL,
    received_date_time_stamp TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL
    And I wanted to query the table to find the range associated with the last inserted row for each 'grade' (e.g. 'A', 'B', 'C', etc), how would I go about that?
    I want something like the following, but I know that this won't work right:
    SELECT
    grade,
    lower_bounding_of_range,
    upper_bounding_of_range,
    max(received_date_time_stamp)
    FROM
    range_test GROUP BY received_date_time_stamp;
    Thanks for your help. . .I'm frustrating myself with this one and I think it should be possible without having to use PL/SQL (i.e. SQL aggregate functions or sub-queries should work).

    Perhaps something along the lines of...
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, empno, ename, hiredate
      2  from emp
      3* order by deptno, empno
    SQL> /
        DEPTNO      EMPNO ENAME      HIREDATE
            10       7782 CLARK      09-JUN-1981 00:00:00
            10       7839 KING       17-NOV-1981 00:00:00
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7369 SMITH      17-DEC-1980 00:00:00
            20       7566 JONES      02-APR-1981 00:00:00
            20       7788 SCOTT      19-APR-1987 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            20       7902 FORD       03-DEC-1981 00:00:00
            30       7499 ALLEN      20-FEB-1981 00:00:00
            30       7521 WARD       22-FEB-1981 00:00:00
            30       7654 MARTIN     28-SEP-1981 00:00:00
            30       7698 BLAKE      01-MAY-1981 00:00:00
            30       7844 TURNER     08-SEP-1981 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, empno, ename, hiredate
      2  from (
      3        select deptno, empno, ename, hiredate
      4              ,row_number() over (partition by deptno order by hiredate desc) as rn
      5        from emp
      6       )
      7  where rn = 1
      8* order by deptno, empno
    SQL> /
        DEPTNO      EMPNO ENAME      HIREDATE
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    SQL>

Maybe you are looking for