calculate data for the last 30 days according to the date of sys

SELECT DT, ITEMCODE, ITEMNAME, QTY
FROM   TABLE1
In above given the query, how do I calculate the details of the amount of the last 30 days, APR, MAY, and JUNE

As the month during JULY, August, the amount of detail is required for the last 30 days (from sysdate), MAY, JUNE, July

Please suggest.

Yogesh

Published by: user12957777 on July 28, 2010 03:16

Hello

CASE expressions can filter data in specific columns:

SELECT     SUM ( CASE
            WHEN dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                         , -3
                         )
            AND  dt <  ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                         , -2
                         )
            THEN qty
           END
         )          AS third_month
,     SUM ( CASE
            WHEN dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                         , -2
                         )
            AND  dt <  ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                         , -1
                         )
            THEN qty
           END
         )          AS second_month
,     SUM ( CASE
            WHEN dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                         , -1
                         )
            AND  dt <               TRUNC (SYSDATE, 'MONTH')
            THEN qty
           END
         )          AS last_month
,     SUM ( CASE
            WHEN dt >= TRUNC (SYSDATE) - 30
            AND  dt <  TRUNC (SYSDATE)
            THEN qty
           END
         )          AS last_30_days
FROM     table1
;

You can do this with GROUP BY, in addition, if you want to separate for each itemname (for example) lines.

I guess some things, like what do you mean by the last 30 days.

If you wish to post a few 9creation TABLE or INSERT sample data) and the results you want from this data, then I could test this.

Tags: Database

Similar Questions

  • query for results last 8 days

    anyone with a query for results last 8 days
    TIMESTAMPADD (SQL_TSI_DAY,-8, CURRENT_DATE), this results in just 1 day results only if I run this query is it display 8th day back results only.

    I want all 8 results back days.
    what someone request for it...

    Published by: user12255470 on April 28, 2010 07:19

    This works very well for me:

    SELECT "D0 time." "" Saw_0 T00 calendar Date ","recipes of F1. " "" Recipes 1-01 (all in all) ' saw_1 'Sample Sales' WHERE 'Time D0. "' T00 calendar Date" BETWEEN TIMESTAMPADD(SQL_TSI_DAY,-8, CURRENT_DATE) AND TIMESTAMPADD (SQL_TSI_DAY-1, CURRENT_DATE) ORDER BY saw_0

    concerning

    John
    http://www.obiee101.blogspot.com/

  • WARNING: Be on the lookout for the RTL8187. SYS malware.

    RTL8187. SYS malware hides very well.
    In my case it was hidden in C:\windows\system32\system32\drivers\rtl8187.sys.
    At first I thought it was a false positive but note the 2 system32 directories.

    He was truly invisible and is accompanied by another false file Realtek as rtlprot.sys, also located in C:\windows\system32\system32\drivers.
    Both were discovered and cleaned by Malwarebytes' Anti-Malware 1.44.  No other program could not find them.

    The real RTL8187. SYS and RtlProt.sys drivers are Realtek wireless LAN drivers.

    The fake pretending to be the real pilots.  Maybe it fools most of the programs in this way.

    My PC has a Realtek wireless adapter and so there were two instances of these two files.  Appropriate one in the location of C:\windows\system32\drivers\ and the other in those well hidden above.
    Maybe that's why they have been discovered.  In a PC without the real drivers Realtek wireless current, it may not be the case.

    The only useful info I can find on google is here:

    http://www.prevx.com/filenames/X57926382501967389-X1/RTL8187.sys.html

    and here:

    http://www.pc1news.com/virus/file-RTL8187-sys-809231.html

    Another thread here someone who has encountered the same malware is:

    http://social.answers.Microsoft.com/forums/en-us/vistahardware/thread/3bdef5be-3b6c-4f21-897D-c8a39e62686d

    I hope this helps.

    Hello

    If they are really malware, then chances are that everything has not been found or deleted. You did
    Reinstall the Realtek drivers?

    See the download here for your version of the device (look in Control Panel - Network).

    http://www.Realtek.com.tw/search/default.aspx?keyword=RTL8187
    If you need search malware here's my recommendations - they will allow you to
    scrutiny and the withdrawal without ending up with a load of spyware programs running
    resident who can cause as many questions as the malware and may be more difficult to detect as the
    cause.

    No one program cannot be used to detect and remove any malware. Added that often easy
    to detect malicious software often comes with a much harder to detect and remove the payload. Then
    its best to be thorough than paying the high price later now too. Check with them to one
    extreme overkill point and then run the cleaning only when you are sure that the system is clean.

    It can be made repeatedly in Mode safe - F8 tap that you start, however, you must also run
    the regular windows when you can.

    Download malwarebytes and scan with it, run MRT and add Prevx to be sure that he is gone.
    (If Rootkits run UnHackMe)

    Download - SAVE - go to where you put it-right on - click RUN AS ADMIN

    Malwarebytes - free
    http://www.Malwarebytes.org/

    Run the malware removal tool from Microsoft

    Start - type in the search box-> find MRT top - right on - click RUN AS ADMIN.

    You should get this tool and its updates via Windows updates - if necessary, you can
    Download it here.

    Download - SAVE - go to where you put it-right on - click RUN AS ADMIN
    (Then run MRT as shown above.)

    Microsoft Malicious - 32-bit removal tool
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=AD724AE0-E72D-4F54-9AB3-75B8EB148356&displaylang=en

    Microsoft Malicious removal tool - 64 bit
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=585D2BDE-367F-495e-94E7-6349F4EFFC74&displaylang=en

    also install Prevx to be sure that it is all gone.

    Download - SAVE - go to where you put it-right on - click RUN AS ADMIN

    Prevx - Home - free - small, fast, exceptional CLOUD protection, working with others
    security programs. It is a single scanner, VERY EFFICIENT, if it finds something to come back
    here or use Google to see how to remove.
    http://www.prevx.com/   <-->
    http://info.prevx.com/downloadcsi.asp  <-->

    Choice of PCmag editor - Prevx-
    http://www.PCMag.com/Article2/0, 2817,2346862,00.asp

    Try the demo version of Hitman Pro:

    Hitman Pro is a second scanner reviews, designed to save your computer from malicious software
    (viruses, Trojans, rootkits, etc.). who infected your computer despite safe
    what you have done (such as antivirus, firewall, etc.).
    http://www.SurfRight.nl/en/hitmanpro

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

    If necessary here are some free online scanners to help the

    http://www.eset.com/onlinescan/

    http://OneCare.live.com/site/en-us/default.htm

    http://www.Kaspersky.com/virusscanner

    Other tests free online
    http://www.Google.com/search?hl=en&source=HP&q=antivirus+free+online+scan&AQ=f&OQ=&AQI=G1

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

    Also follow these steps for the General corruption of cleaning and repair/replace damaged/missing
    system files.

    Run DiskCleanup - start - all programs - Accessories - System Tools - Disk Cleanup

    Start - type this into the search-> find COMMAND to top box and RIGHT CLICK-
    RUN AS ADMIN

    Enter this at the command prompt - sfc/scannow

    How to analyze the log file entries that the Microsoft Windows Resource Checker
    (SFC.exe) program generates in Windows Vista cbs.log
    http://support.Microsoft.com/kb/928228

    Run checkdisk - schedule it to run at the next startup, then apply OK then restart your way.

    How to run the check disk at startup in Vista
    http://www.Vistax64.com/tutorials/67612-check-disk-Chkdsk.html

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

    If we find Rootkits use this thread and other suggestions. (Run UnHackMe)

    http://social.answers.Microsoft.com/forums/en-us/InternetExplorer/thread/a8f665f0-C793-441A-a5b9-54b7e1e7a5a4/

    I hope this helps.

    Rob - bicycle - Mark Twain said it is good.

  • How to get the last date of 3 days for the current month?

    Hello. Guy

    How to get the last date of 3 days for the current month?

    MY OUTPUT WOULD LOOK LIKE THIS

    JANUARY 29, 2016

    JANUARY 30, 2016

    JANUARY 31, 2016


    GUYS HELP ME / / /...

    SQL > select last_day (sysdate) - level + 1 double connect by level<= 3="" order="" by="">

    LAST_DAY)

    ---------

    29 JANUARY 16

    30 JANUARY 16

    31 JANUARY 16

  • How to set up the filter to provide data for the last 7 days

    Hello

    In our environment of BAM Oracle 11 g, we have a data object that stores a date with the datatime data type field. In the report of BAM, we want to display data only for the last 7 days. Not sure how we can configure the filter to "during the" last 7 days

    Can someone help how to achieve this requirement?

    Thank you.

    Please try the following-
    (1) open the chart bar in edit mode.
    (2) in the editor view, click on the button 'Properties', then go to the tab "Format of the value.
    (3) in the tab "Format of the value", to "apply to" drop-down list, select your datetime field.
    (4) in the contiguous list of 'Catégories', select 'TimeUnit' as the category.
    (5) in the following list of 'Type', select 'day of the week.
    6) click OK/application to see the relevant changes.

    Now you should be able to see the day of the week on the horizontal axis 'Thursday', 'Saturday', etc.

  • Remove the last 35 days of a table data

    Hello

    I had a table to n days of data. I need to remove the last 35 days of data. My table has consecutive dates i.e. There were no load weekend or holidays...

    (1) Using INTERVAL command can simply calculate the difference. So it won't work.

    (2) I can use RANK to find the sequence. Is there a better way to write a logic to delete?.

    concerning

    KVB

    PurveshK,

    I think you have the right idea. Just get the ID of the innermost query.

    This should be quite effective, especially if there is an index on the date.

    drop table t;

    create table t:

    Select trunc (sysdate) - level * 2 double dt connect by level<=>

    delete t

    where rowid in)

    Select rn

    de)

    Select the rowid rn, dense_rank() over (order by dt desc) dr

    t

    )

    where dr<=>

    );

    Post edited by: StewAshton:

    Furthermore, the date field must be NOT NULL for the index be used - or even add WHERE DATE IS NOT NULL to the innermost query.

  • Game to "Save history" for 30 days, can only view last 7 days - how can I view the longer history of 7 days?

    "Save history" set to 30 days but can only view last 7 days of history - how can I view the longer history of 7 days?

    According to your troubleshooting info, you have 2 set preferences to update the:
    Browser.history_expire_days
    7

    Browser.history_expire_days. Mirror
    7

    In the address bar, type Subject: config and press ENTER. The subject: config "This might void your warranty!" warning page may appear. Click on that I'll be careful, I promise! to continue on the subject: config page.
    Search for the preference browser.history_expire_days. Right-click on it and select reset. Do the same for other preferences.

  • Want a graphic 'Filesystem space available' for the last 31 days, 7 days and 24 hours on 24

    Using control of cloud EM 12.1.0.4.0.

    For a given host, we are able to get the desired cards as (host > surveillance > CPU detail), which gives us the use of the GPU, CPU etc. load graph. For these cards see you current, last 24 hours, last 7 days and 31 days.

    We need similar graphic for "Filesystem space available (MB or free %)" or the disc.

    I can see the data is present in MS for example (Home > surveillance > the metric), under there are file systems:

    - File system space available (%)

    - Space of available filesystem (MB)

    - File size (MB) system


    But these data are in table form.

    and you can pass the data for these positions... BUT I need to have table smilar to chariot of CPU load with the files above, system information

    Please help with steps, or direct me to documentation.

    Thanks a lot for any input.

    On the page where you see the metric data in a table, select a row (for example a mount point) and you should see the table of the metric for that point inside mounting.

    Below a screenshot shows the graph for a mount point.

    Kind regards

    -Loc

  • Growth of DB per Segment for the last days

    Greetings,


    Our Prod database has grown fast enough for the last 2 weeks, I have a question which gives me the current database size, but I'm trying to run a report to get the size of database/trend for the last 7 days or so which segment (Table or Index, etc.) who have contributed to the growth of the database.

    Thank you.

    @AJ

    Thanks LonutC! Unfortunately this is not what I want, I don't have the means to get the size of the database / total space free etc... on level tablespace, datafile, and object, but the main thing I was looking for is to find the size of the table over time (IE how much a XYZ in MB/GB table has increased during the last 14 days?) The closet script that I've found so far is below the Berloson site.  As you can see in my previous discussions, I could see how much in terms of MB a table set increases every hour in a day and 7-day window as well. I think that will suffice for now, I'll go ahead and close this thread and thank you to all WHO helped

    Please note that you can modify this script to report on any object and not just a Table. But, ALWAYS run any script that you encounter on your Test Env first... just a heads-up...

    > This script displays "total used spaced ' (total size) for a specific table to the Oracle, basically computing the size of the Oracle tables over time:

    a15 col c1 format topic ' snapshot | date'

    a25 col c2 format topic ' table. name '

    format header 999 999 999 c3 col ' space. used | total"

    Select

    TO_CHAR (begin_interval_time, ' dd/mm/yy hh24:mm') c1,

    object_name c2,

    space_used_total c3

    Of

    s dba_hist_seg_stat,

    dba_hist_seg_stat_obj o,

    sn dba_hist_snapshot

    where

    o.Owner = "SCHEMA_07".

    and

    s.obj # o.obj = #.

    and

    SN.snap_id = s.snap_id

    and

    object_name like '% objecname '.

    order by

    begin_interval_time;

    > My results Exp
    > 08/10/15 [HR_EMP_LOG] table has increased to about 8.9 MB to 27.7 MB

    10/08/15 09:08 HR_EMP_LOG 8 914 010

    08/10/15 01:08 HR_EMP_LOG 12,687,676

    10/08/15 12:08 HR_EMP_LOG 20,247,050

    08/10/15 14:08 HR_EMP_LOG 27,776,769

    > On 11/08/15 the table [HR_EMP_LOG] has increased by about 2.9 MB 42 MB

    08/11/15 03:08 HR_EMP_LOG 2 967 158
    08/11/15-06:08 HR_EMP_LOG 10,190,002
    11/08/15 11:08 HR_EMP_LOG 17,068,289
    08/11/15 13:08 HR_EMP_LOG 24,868,673
    11/08/15 17:08 HR_EMP_LOG 30,767,601
    11/08/15 18:08 HR_EMP_LOG 35,149,608
    11/08/15 20:08 HR_EMP_LOG 42,113,748
  • Calculate the fastest path between 2 nodes with the data model for the Oracle network

    Hi all,

    I have Oracle 10 g 2.

    My problem is the following:

    I created a network named ITALIA_NET in the data model for the Oracle network.
    The table of links of this network is named: ITALIA_NET_LINK$.
    The table of the nodes of this network is named: ITALIA_NET_NODE$.

    The table ITALIA_NET_LINK$ contains a field named COST that contains links (in meters) lengths.

    I've already calculated the SHORTEST PATH between two nodes of the network, by using the method of shortestPath() (using the Java API) as shown on "Pro Oracle Spatial for Oracle Database 11 g" manual. Infact, this method makes reference to the COST field for $ ITALIA_NET_LINK to make this calculation.

    Now, I want to calculate the FASTER PATH between two nodes of the network. I have the links (in hours) travel time to make this calculation.

    My idea is to create a new field in ITALIA_NET_LINK$ named Cost2 containing the travel time from the links and then do the math by using the shorthestPath() method, referring to the Cost2 field to $ ITALIA_NET_LINK COST field instead.
    By default, I know that the shorthestPath() method returns the COST field for $ ITALIA_NET_LINK. Is possible to change this setting and do that this method refers to the Cost2 field?

    In the alternative, is another way for the calculation of the fastest way?
    I want to leave the creation of another network as last solution, because I will have other costs of field (Cost3, cos4t,...)

    Thank you much in advance.

    Your approach is good. You will have two networks and you can read them in memory and analyze of shortest path. The shortestPath method is static for the class of NetworkManager. You can use the same method for both networks, once they are read into memory.

    ...
    read the network with time as cost of link
    NetTime network = NetworkManager.readNetwork (dbConnection, 'ITALIA_NET_TIME');
    read the network length as cost of link
    Network netLength = NetworkManager.readNetwork (dbConnection, 'ITALIA_NET_LENGTH');

    calculate the quickest way
    PathTime path = NetworkManager.shortestPath (netTime, startNodeID, endNodeID);
    calculate the shortest path
    PathLength path = NetworkManager.shortestPath (netLength, startNodeID, endNodeID);
    ...

    In the future, if you upgrade to 11g, network data model provides a load on demand (LOD) API that loads only the scores of necessary network in memory during the analysis. This command removes the restriction of the memory of the 10g (in memory API you use) API. API of LOD can handle very large networks and offers more features analysis and modeling capabilities.

    The following link contains the tutorial of NDM LOD API ready for download. Just for your information.
    https://spatial.SampleCode.Oracle.com/servlets/ProjectProcess?PageID=0Zl7oV

    Kind regards
    Jack

  • For the last 2 days everytime I open to MY MSN, it opens in safe mode. I deleted cookies and the history of FF. all other sites open OK. Vista, 64-bit operating system.

    Vista 64 bit OS

    Thanks for the replies, the problem was on the Microsoft site itself and internal glitch for the last 2 days on the garbled causing MY MSN page without graphics and text.

  • I have the time to default iPhone 4 iOS 7.1.2 iPhone App not updated since the last 3 days and also checked all the settings for location and also set as new iPhone always present problem... Please try to fix... Thanx

    I have the time to default iPhone 4 iOS 7.1.2 iPhone App not updated since the last 3 days and also checked all the settings for location and also set as new iPhone always present problem... Please try to fix... Thanx

    Turn off your device and turn it on again. If this does not help, sign out of your account and reconnect.

    In addition, you can try to reset your settings.

    • Press and hold the sleep/wake button
    • Press and hold the Home button
    • Press and hold both buttons until the display turns off and on again with the Apple logo on the subject.

    Alternatively, you can go to settings - general - reset - Reset all settings

  • Why for the last 3 days am I get the update of windows to shut down & boot-up/it takes a lot of time to complete their/TI is aqnnoying!

    I have windows7 home premium - when I stopped, I get updates - then I get them back to the start-up/it happens each time for the last 2 or 3 days-i use my computer toshiba laptop throughout the day and don't ever started day avant-ce that goes? There are unusually long for downloads to update?

    See this discussion: http://answers.microsoft.com/thread/cac55bf2-e271-e011-8dfc-68b599b31bf5 (which now includes a countless number of threads merged to confuse you more).

  • 16 June updated blown all my documents for the last 10 days. Any solution?

    Documents for the last 10 days, all my email settings, all memory of recent activity disappeared.

    Hello Craig,.

    Let's see if the files are actually missing or if they are hidden:

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-files/Unhide-files-and-folders/ca46d3ba-1b51-E011-8dfc-68b599b31bf5

    Best regards

    Matthew_Ha

  • KB2538242 installation every day for the last 4 days(14-17) is this normal?

    Hello

    I was wondering why I have this KB253842 install all update for 4 days last days(14-17) is this normal?

    Just install again and now it seems he still wants me to do again... I saw the story updated and its success since the last 4 days.

    Is this normal?

    Thank you very much... Toni1010

    TONI1010,

    Troubleshooting Windows Update or Microsoft Update when you are repeatedly offered an update

    http://support.Microsoft.com/kb/910339>

    This article also describes how to do to solve the problem when the Automatic Updates downloads and installs the update even repeatedly.

    How to hide or show an update of Windows Vista

    http://www.Vistax64.com/tutorials/72491-Windows-Update.html>

    06/18 / 1112:22: 00 am

Maybe you are looking for