What SQL query I need for this?

I need to execute a SQL query but I don't know how.
To illustrate it, please take a look at some example data:
    ARTICLEID SOLDON    
    1         2005-12-31
    1         2005-11-31
    1         2005-10-31
    1         2005-09-31
    1         2005-08-31
    1         2005-07-31
    1         2005-06-31
    1         2005-05-31
    1         2005-04-31
    1         2005-03-31
    1         2005-02-31
    1         2005-01-31
    1         2004-12-31
    1         2004-11-31
    2         2005-12-31
    2         2005-11-31
    2         2005-10-31
    2         2005-09-31 This is a piece of the sales data for the articles (sales history).
Lets assume that today is the date 2005-12-31.
Two requirements for the query:
1. Get the sales data for the last 12 months.
2. Get only the sales data for articles where there is sales data since at least 6 months.
The result in my example should look like this:
    ARTICLEID SOLDON    
    1         2005-12-31
    1         2005-11-31
    1         2005-10-31
    1         2005-09-31
    1         2005-08-31
    1         2005-07-31
    1         2005-06-31
    1         2005-05-31
    1         2005-04-31
    1         2005-03-31
    1         2005-02-31
    1         2005-01-31 What is the SQL which I need to accomplish this query?

To get all the information from the last 12 months
you will have to use date manipulation.
SELECT add_months(sysdate, -12) from
dual;This gives you the date 12 months ago.
So you will have to select your date between then and
the current date.If I do this I will get this data:
    ARTICLEID SOLDON    
    1         2005-12-31
    1         2005-11-31
    1         2005-10-31
    1         2005-09-31
    1         2005-08-31
    1         2005-07-31
    1         2005-06-31
    1         2005-05-31
    1         2005-04-31
    1         2005-03-31
    1         2005-02-31
    1         2005-01-31
    2         2005-12-31
    2         2005-11-31
    2         2005-10-31
    2         2005-09-31 But I want this data:
    ARTICLEID SOLDON    
    1         2005-12-31
    1         2005-11-31
    1         2005-10-31
    1         2005-09-31
    1         2005-08-31
    1         2005-07-31
    1         2005-06-31
    1         2005-05-31
    1         2005-04-31
    1         2005-03-31
    1         2005-02-31
    1         2005-01-31 I am no native English speaker. What didn't you understand in the two requirements?
Here are my two requirements for the query:
1. Get the sales data for the last 12 months.
2. But get ONLY the sales data for articles where there is sales data since AT LEAST 6 months.
The result can contain as many IDs as you want if the two requirements are met. Its not a trivial SQL statement for me. Please remember that the above data are only for illustration. They are just an example.
There should be a SQL statement for this.
Please tell me if you don't understand my problem. I will try to explain it in a better way if I can.

Similar Messages

  • What licensing do I need for this use ?

    Lets say Im planning an application which does nothing but
    allows the user to upload Adobe PDF documents to our server. Then
    once on the server, parse the values from forms on the PDF's and
    extract the data. We wont be distributing Acrobat reader or any
    other Adobe product, but will provide a link where they can
    download the reader.
    Also, the PDF's would be created by someone with a copy of
    Acrobat pro. These PDF's will need digital signature capability.
    Can Acrobat reader handle signatures ?
    Here are my questions:
    - What licensing do I need, if any, in the above scenario,
    other than that for a copy of Acrobat ?
    - What are my options for capturing digitical signatures
    within a PDF and will the publicly available version of Acrobat
    reader allow the end user to sign the documents, provided they
    install the extra requirements for handling the signatures ?

    This isn't the correct forum for this topic, but I may be
    able to get you started...
    The licensing restrictions on gathering form data from PDFs
    is outlined in the EULA for Reader, I believe there is a limit of
    500 copies, but I could be wrong ... you should look at the EULA to
    be sure.
    Beyond that, try posting to the
    Acrobat
    Forums or contacting a sales rep at Adobe, they may be able to
    advise you further.

  • Tweak for sql query - help needed for smalll change

    Hi.
    I am trying to run a script that checks for used space on all tablespaces and returns the results.
    So far so good:
    set lines 200 pages 2000
    col tablespace_name heading 'Tablespace' format a30 truncate
    col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
    col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
    col used_space_mb heading 'MB|Used' format 9G999G999D99
    col free_space_mb heading 'MB|Free Till Max' like used_space_mb
    col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
    col pct_used heading '%|Used' format 999D99
    col pct_free heading '%|Free' like pct_used
    break on report
    compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
    select
    alloc.tablespace_name,
    (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
    free.free_space_mb free_space_ext_mb,
    ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
    FROM (SELECT tablespace_name,
    ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
    ROUND(SUM(bytes)/1048576) total_allocspace_mb
    FROM dba_data_files
    WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    GROUP BY tablespace_name) alloc,
    (SELECT tablespace_name,
    SUM(bytes)/1048576 free_space_mb
    FROM dba_free_space
    WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    GROUP BY tablespace_name) free
    WHERE alloc.tablespace_name = free.tablespace_name (+)
    ORDER BY pct_used DESC
    The above returns something like this:
    MB MB % %
    Tablespace Used Free Till Ext Used Free
    APPS_TS_ARCHIVE 1,993.13 54.88 97.32 2.68
    APPS_TS_TX_IDX 14,756.13 1,086.88 91.37 8.63
    APPS_TS_TX_DATA 20,525.75 594.25 80.18 19.82
    APPS_TS_MEDIA 6,092.00 180.00 74.37 25.63
    APPS_TS_INTERFACE 13,177.63 366.38 71.49 28.51
    The above works fine, but I would like to further change the query so that only those tablespaces with free space less than 5% (or used space more than 95%) are returned.
    I have been working on this all morning and wanted to open it up to the masters!
    I have tried using WHERE pct_used > 95 but to no avail.
    Any advice would be appreciated.
    Many thanks.
    10.2.0.4
    Linux Red Hat 4.

    Thanks for that.
    What is confusing is that the below query works for every other (about 10 others) database but not this one (?)
    SQL> set lines 200 pages 2000
    SQL>
    SQL> col tablespace_name heading 'Tablespace' format a30 truncate
    SQL> col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
    SQL> col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
    SQL> col used_space_mb heading 'MB|Used' format 9G999G999D99
    SQL> col free_space_mb heading 'MB|Free Till Max' like used_space_mb
    SQL> col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
    SQL> col pct_used heading '%|Used' format 999D99
    SQL> col pct_free heading '%|Free' like pct_used
    SQL>
    SQL> break on report
    SQL> compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
    SQL>
    SQL> select /*+ALL_ROWS */
    2 alloc.tablespace_name,
    3 alloc.total_maxspace_mb,
    4 alloc.total_allocspace_mb,
    5 (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
    6 free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb) free_space_mb,
    7 free.free_space_mb free_space_ext_mb,
    8 ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    9 ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
    10 FROM (SELECT tablespace_name,
    11 ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
    12 ROUND(SUM(bytes)/1048576) total_allocspace_mb
    13 FROM dba_data_files
    14 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    15 GROUP BY tablespace_name) alloc,
    16 (SELECT tablespace_name,
    17 SUM(bytes)/1048576 free_space_mb
    18 FROM dba_free_space
    19 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    20 GROUP BY tablespace_name) free
    21 WHERE alloc.tablespace_name = free.tablespace_name (+)
    22 ORDER BY pct_used DESC
    23 /
    ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    ERROR at line 8:
    ORA-01476: divisor is equal to zero

  • HT2731 i have an Apple ID and want to get free ringtones on my iPhone 4.  What more do i need for this?

    I have an Apple ID and want to get free ringtones on my iPhone 4.. What more is needed to do this?  I have worked on this all day and I am very frustrated.

    You could have multiple libraries on one computer and then hold the Shift key down when startng iTunes to choose which library to use.
    Or you can have everything in one Library with organized media and apps using multiple Apple IDs.
    Which would you choose?

  • What battery do I need for this please?

      Model Name:          MacBook
      Model Identifier:          MacBook2,1
      Processor Name:          Intel Core 2 Duo
      Processor Speed:          2 GHz
      Number Of Processors:          1
      Total Number Of Cores:          2
      L2 Cache:          4 MB
      Memory:          2 GB
      Bus Speed:          667 MHz
      Boot ROM Version:          MB21.00A5.B07
      SMC Version (system):          1.17f0
      Serial Number (system):          W873011PYA7
      Hardware UUID:          00000000-0000-1000-8000-0019E344147B
      Sudden Motion Sensor:
      State:          Enabled

    http://store.apple.com/us/product/MA561LL/A/rechargeable-battery-13-inch-macbook -white
    http://store.apple.com/us/product/MA566LL/A/rechargeable-battery-13-inch-macbook -black

  • Hi! I can't upgrade my iTunes 10.3.1.55 on my Windows XP 2002 SP3 to the latest version of iTunes. Got the message: "A problem has occured with the Windows Installer-package. A program needed for this installation could not be run." What to do?

    Hi! I can't upgrade my iTunes 10.3.1.55 on my Windows XP 2002 SP3 to the latest version of iTunes. Got the message: "A problem has occured with the Windows Installer-package. A program needed for this installation could not be run." What to do?

    Perhaps let's first try updating your Apple Software Update.
    Launch Apple Software Update ("Start > All Programs > Apple Software Update"). Does it launch and offer you a newer version of Apple Software Update? If so, choose to install just that update to Apple Software Update. (Deselect any other software offered at the same time.)
    If the ASU update goes through okay, try another iTunes install. Does it go through without the errors this time?

  • I have a Mac Pro 4,1 quad core intel Xeon running mac OSX 10.6.8 and I have just moved studios and now need to use the Internet wirelessly but there's no airport facilities on this model can anyone tell me what model of airport card I would need for this

    I have a Mac Pro 4,1 quad core intel Xeon running mac OSX 10.6.8 and I have just moved studios and now need to use the Internet wirelessly but there's no airport facilities on this model can anyone tell me what model of airport card I would need for this mac

    Instead of getting a wireless card for the Mac Pro, you might want to consider getting an 802.11ac wireless bridge device that would enable you to connect more than one device to it by Ethernet cable and to eventually take advantage of the faster 802.11ac wireless standard.

  • Hi!  I cant conect The face time betwen my iPad ,iPod and iPhone, please help me,what i need for this issue?

    Hi!  I cant conect The face time betwen my iPad ,iPod and iPhone, please help me,what i need for this issue?

    What is it doing when you try to facetime? also if you are using the same apple Id/email on each device, it wont work.

  • What all is needed for this type of Flash Design Studio

    What all is needed for this type of Flash Design Studio.
    There are a couple of sites out there that use both flash and
    shockwave. I am looking ot get somethign like this started and need
    some help getting pointed in the right direction. here are some
    examples:
    http://www.uberprints.com/studio/
    http://www.customavenue.com/online-design-studio/online-design-studio.html
    https://www.youdesignit.com/youdesignit.cfm
    http://www.pixeltees.com/make

    Rclarkhaddock,
    > What all is needed for this type of Flash Design Studio.
    There
    > are a couple of sites out there that use both flash and
    shockwave.
    Of the examples you showed, I saw Flash (Adobe Flash),
    Shockwave (Adobe
    Director), and JavaScript, but never a combination on the
    same site. (It
    might make sense to combine Flash with JavaScript or
    Shockwave with
    JavaScript, but not really to combine Flash with Shockwave.)
    > I am looking ot get somethign like this started and need
    some help
    > getting pointed in the right direction.
    Any of the above technologies will do it. You could also use
    a Java
    applet or even a .NET solution of some kind, so the choice
    you take will
    depend largely on what platform you want to support and code
    for. This sort
    of project will require significant amounts of custom
    programming. My
    personal approach would be to use Flash, mainly because of
    the popularity of
    the plugin. The Shockwave example looks beautiful, and I
    started out years
    ago using Director, but fewer people nowadays have the
    Shockwave plugin
    installed. It doesn't look like any of the sites shown use 3D
    modeling,
    which is the only relevant feature that Shockwave has over
    the other
    approaches. JavaScript (probably some Ajax approach) would
    work -- as
    seen -- but then you're dealing with compatibility issues
    among various
    JavaScript implementations in the great variety of browsers
    out there.
    Flash minimizes that, in my opinion.
    All you really "need" to produce what you've seen is Flash
    and some sort
    of database back end (MySQL, say), which means you'll need a
    bit of
    middleware (PHP, ASP, Cold Fusion, etc.) to act as your
    ambassador between
    Flash and the database.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • What r the tables used for this report.

    hi all..
    i am a fresher for ABAP. i need the help.
    what r the tables used for this report.
    Reports provide pending order details according to Material wise and customer wise for particular month.
    thanks in advance
    RK.Ashokkumar.

    Hi Ashok,
    this is easy to do.
    Open Two SAP Screen with same user ID.
    Run SQL trace using ST05 transaction.Open ST05 transaction in One and make
    Trace on ,Run the report in another screen.
    Once report run is over.End the trace process and click on display trace in same ST05 transaction.There is a click button on ST05 Transaction screen to start trace
    process,End trace process and Display track process.
    The SQL trace will  give you all the table details which is used in that particular report.
    You have not mentioned about the report name so I have suggested this way.
    regards,nishant
    Please reward if this helps

  • What technical components are needed for integration of SAP BI and BO?

    Hello,
    What technical components are needed for integration of SAP BI and BO?

    Hi,
    you need to setup a BOBJ server (eg. BusinessObjects Enterprise XI 3.1 or BO Edge 3.1) and then install the BusinessObjects integration Kit for SAP on the same machine your BOBJ server runs.
    In order to build reports you can either use Crystal Reports (eg Install Crystal Report Designer 2008 V1 if you have an XI 3.1 server installed), WebIntelligence (Install the Business Objects XI 3.1 Client Tools in order to be able to build universes), BusinessObjects Voyager or XCelsius. Please note that you have to always install the BOBJ integration Kit for SAP (should be the same version as your server and client installation) on your clients AFTER you installed one or more of the above client tools.
    Please take again a look at the following link for more detailed information (from Ingo) on this:
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a00ee3b2-5283-2b10-f1bf-8c6413e0898f]
    Regards,
    Stratos

  • Can we implement the custom sql query in CR for joining the two tables

    Hi All,
    Is there anyway to implement the custom sql query in CR for joining the two tables?
    My requirement here is I need to write sql logics for joining the two tables...
    Thanks,
    Gana

    In the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
    Log on to your data source if necessary.
    Under your data source, double-click the Add Command node.
    In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
    For example:
    SELECT
        Customer.`Customer ID`,
        Customer.`Customer Name`,
        Customer.`Last Year's Sales`,
        Customer.`Region`,
        Customer.`Country`,
        Orders.`Order Amount`,
        Orders.`Customer ID`,
        Orders.`Order Date`
    FROM
        Customer Customer INNER JOIN Orders Orders ON
            Customer.`Customer ID` = Orders.`Customer ID`
    WHERE
        (Customer.`Country` = 'USA' OR
        Customer.`Country` = 'Canada') AND
        Customer.`Last Year's Sales` < 10000.
    ORDER BY
        Customer.`Country` ASC,
        Customer.`Region` ASC
    Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
    Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
    For more information about creating parameters, see To create a parameter for a command object.
    Click OK.
    You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
    Note:
    To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
    By default, your command is called Command. You can change its alias by selecting it and pressing F2.

  • What charger do I need for my 2008 macbook pro 15"

    what charger do I need for my 2008 macbook pro 15"?

    This one:
    http://store.apple.com/us/product/MC556LL/B/apple-85w-magsafe-power-adapter-for- 15-and-17-inch-macbook-pro
    Ciao.

  • What app do i need for my epson 600 printer to work with my ipad

    what app do i need for my epson 600 printer to work with my ipad

    Hi,
    You are asking at a wrong forum, anyway firstly please check to see is your printer in this list ? 
    http://support.apple.com/kb/ht4356
    If Yes, please follow this checklist and fix:
    iPad: http://www.apple.com/support/ipad/assistant/airprint/
    If No, check with Epson
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • What are the tables used for this Report

    hi all..
    i am a fresher for ABAP. i need the help.
    what r the tables used for this report.
    Reports provide pending order details according to Material wise and customer wise for particular month.
    thanks in advance
    RK.Ashokkumar.
    9994262112.

    hi
    good
    try with these tables,
    MARA
    KNA1
    thanks
    mrutyun^

Maybe you are looking for

  • Error While Transporting the DSOs

    Hi Experts, I am transporting a DSO from DEV to QA in 7.0 system.While transporting the DSO, i am getting the below mentioned error. The creation of the export DataSource failed Reading the Metadata of APMD0009 ... Creating DataSource 8APMD0009 ... P

  • Itunes wont open after updating. windows 7 ultimate

    Hi, I have been using itunes for perfectly fine then when i updated it, it stopped working. The update required a restart but i elected to manually restart, but i believe i forgot to and tried to open itunes and i got an error saying "iTunes has stop

  • So how long does it take to load a 160GB iPod using the Convert Higher ...

    I have a 160GB Gen 5 that I bought when first released back in the day when they were $400. Through a number of changes, the most recent being the advent of the Convert Higher Bitrate Songs to 128bit AAC feature, I decided to look at what more music

  • Photos menu dissapears from Apple TV

    Photos menu dissapears from Apple TV as soon as I upload my library from my computer (the one that is synching with ATV) If I go to sources and I select ATV instead of my library the photos menu is back. In either case the photos are there as I can s

  • Does Not Sync, Stuck

    When I went to go sync my iPod, it shows up on the screen and the iPod seems like it is starting to sync. But then it doesn't and the screen on the iPod goes back the cord picture where it says "Connected_Eject before disconnecting." When I click syn