Need help for a query

Dear all,
I have data in a table with 3 columns.
Tabke name---test & columns are ....
Proeductioncode varchar2(5);
revisionno varchar2(3);
dateadopted char(8);
SELECT PRODUCTIONCODE,
REVISIONNO,
dateadopted
FROM test
where
productioncode ='CI50E';
output should be
productioncode revisionno dateadopted
     CI50E     004     20110125     
     CI50E     001     20101104     
     CI50E     003     20110320     
     CI50E     002     20101214     
My requirement is
I wanna display records which are dateadopted is > sysdate and
one record which is less than sysdate, which is the max(<sysdate)..
from the data above, the output should be
CI50E     003     20110320     
CI50E     004     20110125     
Please help me get this output. we need to write it in a select query.

Sorry I don't have a database available to test - missed to join by productioncode :( grouping by revisionno caused more than one row being returned :(
No need to send data. I added a data providing subquery. Will take shot when I get to the database, but I might not be able to post from the office
with
/* generating test data */
test as
(select 'CI50E' productioncode,'004' revisionno,'20110125' dateadopted from dual union all /* 003 if increasing by date */
select 'CI50E','001','20101104' from dual union all
select 'CI50E','003','20110320' from dual union all                                        /* 004 if increasing by date */
select 'CI50E','002','20101214' from dual union all
select 'XI50Y','001','20110220' from dual union all
select 'XI50Y','002','20110220' from dual union all
select 'XI50Y','003','20110304' from dual 
/* end of test data generation */
SELECT productioncode,revisionno,dateadopted
  FROM (select productioncode,revisionno,dateadopted
          from test a
         where (dateadopted > to_char(sysdate,'yyyymmdd'))
            or dateadopted = (select max(dateadopted)
                                from test
                               where productioncode = a.productioncode
                                 and dateadopted < to_char(sysdate,'yyyymmdd')
ORDER BY PRODUCTIONCODERegards
Etbin
Edited by: Etbin on 20.2.2011 21:58
did some alignment
Edited by: Etbin on 21.2.2011 7:39
missing right parenthesis added, group by clause removed since there is just a single product
Edited by: Etbin on 21.2.2011 7:52
some more data edit

Similar Messages

  • Needs help for the query

    Hi All,
    I had atable containing 2 columns like NO and Grade.
    ID Grade DEPTID
    1 A 10
    2 E 20
    3 D 20
    4 C 30
    5 H 10
    6 K 10
    7 B 30
    8 L 30
    9 R 20
    i need output as
    DEPTID Employees and grades in the DEPT
    10 1 A , 5 H , 6 K
    20 2 E , 3 D , 9 R
    30 4 C , 7 B , 8 L
    Please anyone give me query for this.
    thanks in advance.
    rampa

    STRAGG for string aggregation. One of the most frequent ask question over here.
    Here a forum search for you.
    Of course, the options depend of version you are on.
    Nicolas.

  • Need help for the query columns to rows

    Hi everyone,
    I have two tables TABLE1 and TABLE2; TABLE1 is Master table,TABLE2 is child table.
    The key for TABLE1 is C1 column
    The key for TABLE2 is C1,C_MONTH Columns
    The sample data is as follows
    TABLE1
    ======
    C1 C2
    1 A
    2 B
    3 C
    4 D
    TABLE2
    ======
    C1 C_MONTH C3
    1 JAN AAA
    1 FEB BBB
    1 MAR CCC
    1 APR DDD
    2 JAN ZZZ
    2 FEB YYY
    2 MAR XXX
    2 APR UUU
    I want to display the data as follows
    1 A JAN AAA FEB BBB MAR CCC APR DDD
    2 B JAN ZZZ FEB YYY MAR XXX APR UUU
    Can any one help me how to write this query?
    Thanks in advance

    [email protected] wrote:
    Thanks for the update
    but I want the out put as column values rather than one column as follows
    C1 C2 J_MONTH J_VALUE F_MONTH F_VALUE M_MONTH M_VALUE A_MONTH A_VALUE
    1 A JAN AAA FEB BBB MAR CCC APR DDD
    2 B JAN ZZZ FEB YYY MAR XXX APR UUUThis is a standard pivot.
    In 10g or below you can do something like...
    SQL> ed
    Wrote file afiedt.buf
      1  with table1 as (
      2                  select 1 c1, 'A' c2 from dual union all
      3                  select 2, 'B' from dual union all
      4                  select 3, 'C' from dual union all
      5                  select 4, 'D' from dual
      6                 ),
      7       table2 as (
      8                  select 1 c1, 'JAN' C_MONTH,'AAA' C3 from dual union all
      9                  select 1,'FEB','BBB' C3 from dual union all
    10                  select 1,'MAR','CCC' C3 from dual union all
    11                  select 1,'APR','DDD' C3 from dual union all
    12                  select 2,'JAN','ZZZ' C3 from dual union all
    13                  select 2,'FEB','YYY' C3 from dual union all
    14                  select 2,'MAR','XXX' C3 from dual union all
    15                  select 2,'APR','UUU' C3 from dual
    16                 )
    17  -- end of test data
    18  select table1.c1, table1.c2
    19        ,max(decode(c_month, 'JAN', c_month)) as jan_month
    20        ,max(decode(c_month, 'JAN', c3)) as jan_value
    21        ,max(decode(c_month, 'FEB', c_month)) as feb_month
    22        ,max(decode(c_month, 'FEB', c3)) as feb_value
    23        ,max(decode(c_month, 'MAR', c_month)) as mar_month
    24        ,max(decode(c_month, 'MAR', c3)) as mar_value
    25        ,max(decode(c_month, 'APR', c_month)) as apr_month
    26        ,max(decode(c_month, 'APR', c3)) as apr_value
    27  from table1 join table2 on (table1.c1 = table2.c1)
    28* group by table1.c1, table1.c2
    SQL> /
            C1 C JAN JAN FEB FEB MAR MAR APR APR
             1 A JAN AAA FEB BBB MAR CCC APR DDD
             2 B JAN ZZZ FEB YYY MAR XXX APR UUU
    SQL>From 11g upwards you can use the new PIVOT keyword.

  • Need help for SQL Query

    Hi Friends,
    I am using below query to genearet one report.
    {code}
    distinct a.plan_id,
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = a.plan_id)
    "EXT_PAN_REF",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = b.depends_on_ba_plan_id)
    "EXT_PAN_REF1",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = c.drp_plan_id)
    "EXT_PAN_REF2",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = d.srp_plan_id)
    "EXT_PAN_REF3",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = e.DRP_TO_DRP_PLAN_ID)
    "EXT_PAN_REF4",
    (SELECT external_plan_ref
    FROM bk9_t_plan
    WHERE plan_id = f.srp_plan_id)
    "EXT_PAN_REF5"
    FROM BK9_T_BUSINESS_ACTIVITY a,
    BK9_T_BA_DEPENDENCY b,
    BK9_T_BA_DRP_DEP c,
    BK9_T_BA_SRP_DEP d,
    BK9_T_DRP_DEPENDENCY e,
    BK9_T_SYSTEM_DEPENDENCY f
    WHERE     a.plan_id = b.ba_to_ba_plan_id
    AND a.plan_id = c.ba_plan_id
    AND a.plan_id = d.ba_plan_id
    AND c.drp_plan_id = e.DRP_TO_DRP_PLAN_ID
    AND e.DRP_TO_DRP_PLAN_ID = f.drp_plan_id
    {code}
    My output is like this :
    {code}
    22767 19093 19095 19049  19049 19059
    22767 19093 19095 19049  19049 19060
    22767 19093 19095 19062  19062 19060
    22767 19093 19095 19062  19062 19061
    22768 19094 19093 19062  19062 19060
    22768 19094 19093 19062  19062 19061
    {code}
    But What i am looking is like this.
    {code}
    22767 19093 19095 19049  19049 19059
    22767                                               19060
    22767 19093 19095 19062  19062 19060
    22767                                              19061
    22768 19094 19093 19062 19062 19060
    22768                                              19061
    {code}
    Please help.

    Hi,
    Could you please illuminate our minds and spend a bit of time in explaining the logic? That will be much easier without reading the crystal ball which nobody has it here.
    Please read: Re: 2. How do I ask a question on the forums?
    And please provide sample data (create table and insert statement), description of the logic, database version and everything else which is specified in the FAQ
    Regards.
    Al

  • Need help for SQL Query last 5 mins Records.

    I need the data between the last five minutes from a table which contains Timeid Column and data type is date.
    select sysdate,(sysdate-((mod(extract(minutes from systimestamp),5)+5)/24/60)-((extract(second from systimestamp))/24/60/60)) Start_date,
    (sysdate-((mod(extract(minutes from systimestamp),5))/24/60)-((extract(second from systimestamp))/24/60/60)) End_Date;
    Suppose now the current time is 01:20:00PM then the output should be from
    Current Date & Time Start Date & Time End Date & Time
    10/18/2007 01:20:00 10/18/2007 01:10:01 10/18/2007 01:15:00
    Suppose now the current time is 01:20:01 then the output should be from
    Current Date & Time Start Date & Time End Date & Time
    10/18/2007 01:20:01 10/18/2007 01:15:01 10/18/2007 01:20:00
    The output i am getting where as i need the output shown above.
    Current Date & Time Start Date & Time End Date & Time
    10/18/2007 01:20:01 10/18/2007 01:14:59 10/18/2007 01:19:59

    SQL> select sysdate,
      2       sysdate -
      3           (decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
      4            mod(to_number(to_char(sysdate,'sssss')),300))+300)/(24*60*60 )
      5                     st_time,
      6         sysdate -
      7           decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
      8            mod(to_number(to_char(sysdate,'sssss')),300))/(24*60*60 )
      9                         end_time
    10  from dual;
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:39:46 18-oct-2007 16:30:00 18-oct-2007 16:35:00
    SQL> /
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:39:59 18-oct-2007 16:30:00 18-oct-2007 16:35:00
    SQL> /
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:40:00 18-oct-2007 16:30:00 18-oct-2007 16:35:00
    SQL> /
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:40:01 18-oct-2007 16:35:00 18-oct-2007 16:40:00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Need help for Transfer PO

    need help for Transfer PO.
    i need help for to transfer PO from one season to onther season. pleas ehelp me how to proceed and how 2 approach the process.
    if any code is there please provide  me

    follow the link
    it may help you
    MM SCENARIO
    https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=abapcodetotransferpurchaseorder&adv=true&sdn_author_name=&sdn_allusernamesofthread=&sdn_category=&sdn_forum=&sdn_updated_on_comparator=GE&sdn_updated_on=&sortby=cm_rnd_rankvalue
    reward if helpful
    Edited by: sharad narayan on Apr 8, 2008 3:16 PM

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Need Help on below Query.

    Hi All,
    Need Help on below Query.
    Consider,
    "test9" Table Data in COLUMN "Name" AS
    Name
    =====
    'a'
    'b'
    'c'
    'd'
    'e'
    I am writing a query as :
    SELECT * FROM test9 WHERE Name IN ('a','b','c','d','e','f','g')
    I want result set as , It should show data as -
    'f'
    'g'
    i.e. data which does not exists in the table and which is give in in clause
    Is it possible in a single query.

    You can put the data that is to be checked for into a table instead or an inline view, for example:
    with t as
    (select 'a' as c1 from dual
    union all
    select 'b' from dual
    union all
    select 'c' from dual
    union all
    select 'd' from dual
    union all
    select 'e' from dual)
    select c1 from (select 'a' as c1 from dual
    union all
    select 'b' from dual
    union all
    select 'c' from dual
    union all
    select 'd' from dual
    union all
    select 'e' from dual
    union all
    select 'f' from dual
    union all
    select 'g' from dual)
    minus
    select c1 from t
    C
    f
    g
    2 rows selected.

  • Need help defining a query

    Hi everyone...
    I need help with this query. The table 'cobros' has a primary key defined by id_cliente + id_cobro. I pretend to classify rows by COUNT(id_cobro) which are between a date range.
    A client could have 1 or 2 or 3 rows per day, no more for a specific date. I would like to get first, all clients with COUNT(id_cobro) = 1, all clients with COUNT(id_cobro) = 2, and finally all clients with COUNT(id_cobro) = 3.
    Something similar to:
    1 SELECT id_cliente, COUNT(id_cobro) FROM cobros
    2 WHERE fecha_proximo_cobro >= '2011-05-30 00:00'
    3 AND fecha_proximo_cobro <= '2011-05-30 23:59'
    4 AND COUNT(id_cobro) = 1
    5 GROUP BY id_cliente
    The fourth line is the problem. It doesn't work.
    Thanks in advance!!!
    Mario

    Maybe you are looking for something like this?
    SELECT id_cliente
         , COUNT(*)   AS cnt
    FROM   cobros
    WHERE  fecha_promixo_cobro BETWEEN TO_DATE('2011-05-30 00:00','YYYY-MM-DD HH24:MI') AND TO_DATE('2011-05-30 23:59','YYYY-MM-DD HH24:MI')
    GROUP BY id_cliente
    ORDER BY 2
           , 1Also, NEVER rely on implicit data type conversion as you have (you provide a STRING not a DATE).
    Edited by: Centinul on Jun 2, 2011 12:36 PM
    Fixed syntax error.

  • I have problem with buying in games , I got the massage that the purchased can not be completed , please contact iTunes support.. I need help for my case please

    I have problem with buying in games , I got the massage that the purchased can not be completed , please contact iTunes support.. I need help for my case please

    http://www.apple.com/support/itunes/contact/

  • Need help for Format HD

    Hi I need Help for Formating HD so Wat Key need hold on start up for format HD I apprciated you Help

    Jesus:
    Formatting, Partitioning Erasing a Hard Disk Drive
    Warning! This procedure will destroy all data on your Hard Disk Drive. Be sure you have an up-to-date, tested backup of at least your Users folder and any third party applications you do not want to re-install before attempting this procedure.
    • With computer shut down insert install disk in optical drive.
    • Hit Power button and immediately after chime hold down the "C" key.
    • Select language
    • Go to the Utilities menu (Tiger) Installer menu (Panther & earlier) and launch Disk Utility.
    • Select your HDD (manufacturer ID) in left side bar.
    • Select Partition tab in main panel. (You are about to create a single partition volume.)
    • _Where available_ +Click on Options button+
    +• Select Apple Partition Map (PPC Macs) or GUID Partition Table (Intel Macs)+
    +• Click OK+
    • Select number of partitions in pull-down menu above Volume diagram.
    (Note 1: One partition is normally preferable for an internal HDD.)
    • Type in name in Name field (usually Macintosh HD)
    • Select Volume Format as Mac OS Extended (Journaled)
    • Click Partition button at bottom of panel.
    • Select Erase tab
    • Select the sub-volume (indented) under Manufacturer ID (usually Macintosh HD).
    • Check to be sure your Volume Name and Volume Format are correct.
    • Click Erase button
    • Quit Disk Utility.
    cornelius

  • Need help for my requirement...

    Need help for my requirement...
    Hello Experts,
    I have report where users can input the company, housebank, account ID and posting date.
    Now in one column of my report named 'Cash in Bank', I need to get all postings from cash
    accounts with GL code ending in '0'. Now, I know that I can get the amounts in BSIS/BSAS
    but how do I link it with the proper bank and account?
    For example:
                       Cash in Bank
    Bank A
      Account ID 1     1,000,000
      Account ID 2     25,000,000
    Hope you can help me guys. Thank you and take care!

    hi Viraylab,
    each house bank you can find in table T012, in T012K you'll find the bank accounts to the housebank, the G/L account will be in T012K-HKONT.
    hope this helps
    ec

  • Need help for flash builder

    i need help for flash builder 4 and papervison 3d. I need to create a slider with it ranges of value from 10 to 50 to adjust the camera values for the camera.fov and also need to create it for the yaw of the object from 0 to 360. I try to look for any slider event and classes in this program but cant find any, btw, i need to use the AS only project file.
    here is my codes:
    can you please tell me how i should modify the codes?
    package
        import flash.display.BitmapData;
        import flash.display.Sprite;
        import flash.events.Event;
        import org.papervision3d.materials.BitmapFileMaterial;
        import org.papervision3d.materials.BitmapMaterial;
        import org.papervision3d.objects.primitives.Sphere;
        import org.papervision3d.view.BasicView;
        [SWF (width="800", height="600", backgroundColor="0x000000",frameRate="30")]
        public class EarthBitmap extends BasicView
            private var sphere:Sphere;
            public function EarthBitmap()
                super(800 , 600);
                var earthmaterial:BitmapFileMaterial = new BitmapFileMaterial("../assets/Earth.jpg");
                sphere = new Sphere(earthmaterial,100,20,18);
                camera.fov = 25;
                scene.addChild(sphere);
                addEventListener(Event.ENTER_FRAME,rotateSphere);
            public function rotateSphere(evt:Event):void
                sphere.yaw(0.2);
                singleRender();

    Turn the click handler into a full on separate function. Then store all the views in an array and use Math.rand() to randomly choose one.
    Something like this:
    <fx:Script>
         <![CDATA[
              var questionsArray:Array = {question2,question3,question5,questionRed,questionGeography};
              function buttonClickHandler(event:MouseEvent){
                   var randomProblem:int = Math.floor(Math.random()*(questionsArray.length));     //generates a random integer between 0 and the total number of questions in the array (arrays are 0-based)
                   navigator.pushView(questionsArray[randomProblem]);
         ]]>
    </fx:Script>
    <s:Button id="randomProblemButton" label="Next Problem" click="buttonClickHandler(event)" />
    Haven't tested that, but something along that line should work

  • Need help for importing oracle 10G dump into 9i database

    hi, Someone help me to import oracle 10G dump into 9i database. I'm studying oracle . Im using oracle 10G developer suite(downloaded from oracle) and oracle 9i database. I saw some threads tat we can't import the higher version dumps into lower version database. But i'm badly need help for importing the dump...
    or
    someone please tell me the site to download oracle 9i Developer suite as i can't find it in oracle site...

    I didnt testet it to import a dump out of a 10g instance into a 9i instance if this export has been done using a 10g environment.
    But it is possible to perform an export with a 9i environment against a 10g instance.
    I am just testing this with a 9.2.0.8 environment against a 10.2.0.4.0 instance and is working so far.
    The system raises an EXP-00008 / ORA-37002 error after exporting the data segments (exporting post-schema procedural objects and actions).
    I am not sure if it is possible to perform an import to a 9i instance with this dump but maybe worth to give it a try.
    It should potentially be possible to export at least 9i compatible objects/segments with this approach.
    However, I have my doubts if this stunt is supported by oracle ...
    Message was edited by:
    user434854

  • Need Help for Nokia 6500 slide

    Hi all I'm A new Guy here ,
    But I do really need help for hard reset my phone
    I already try *#7073# But It doesn't work ,
    If Anybody know to make a hard reset please help

    rwss wrote:
    I'v got te same problem with my 6500 Slide, is there a button combination that we have to press
    to hard reset the 6500 Slide?!
    How does the 6500 slide hard reset?
    That's simple.
    All you have to do is:
    From MENU goto SETTINGS, When there scroll down and select 'Restore Factory Setting'.
    There are two options in there:
    "Restore Settings only"
    and
    "Restore all"
    Select "Restore All"
    When done the phone will delete every thing on the Phone memory(C:\)(contacts,picture,messages etc)
    and also restore phone to its original settings and will restart.
    This proceedure is mostly common on S40 phone.
    Hope this explain and solve the problem.

Maybe you are looking for