Query to group values with date

Dear all,
I have a table tdate with 13 columns with one column named trandate
with value like "11/07/2008 18:00:19"
NOw I want to retrieve values from the table like
select count(*) from trandate where where ttype = '081' and T_FILE like 'monT%';
I want to count the records for every month like
jan-2009 - 120 (120 is the number of records satifying the above condition and belong to the period jan 2009 (derived from trandate column)
feb-2009 - 150 (150 is the number of records satifying the above condition and belong to the period feb 2009 (derived from trandate column)
How can i rewrite the query
Thanks
Kai
Edited by: KaiS on Feb 1, 2011 4:23 AM

Something like this?
SELECT TO_CHAR(trandate,'mon-YYYY') AS trandate
     , cnt
FROM
        SELECT trandate
             , COUNT(*) AS cnt
        FROM   trandate
        WHERE  ttype = '081'
        AND    t_file LIKE 'monT%'
        GROUP BY trandate
        ORDER BY 1
)If that doesn't work out then please post:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • JDBC MS Access--- cannot extract entry with null value with data type Meta

    I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
    The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
    Any advice will be appreciated! thanks!
    Following are the table description and JDBC code:
    test table has the following attributes:
    Field name Data Type
    name Text
    label Memo
    table contents:
    name label
    me null
    you gates
    Code:
    String query = "SELECT name, label FROM test where name like 'me' ";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next())
    String name = rs.getString("name");
    rs.getString("val");
    String label = rs.getString("label");
    System.out.println("\t"+name+"\t"+label);
    catch (SQLException ex)
    System.out.println(ex.getSQLState());
    System.out.println(ex.getErrorCode());
    System.out.println("in sqlexception");
    output:
    C:\Temp\SEFormExtractor>java DBTest
    yet SELECT name, label FROM test
    null
    0
    in sqlexception

    The question is how to extract null entry with data type memo?Okay, what you need to do is this:
    if (rs.getString("val") == null)
      // do something
    }This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception.

  • Writing query to Oracle DB with DATE field in it.

    When I try to execute the following query on Oracle DB I get an exception. I know that the problem is with Date representation on the query string. Please, if anyone knows how to make it work help me.
    query = "INSERT INTO MYTABLE (NAME , BIRTHDAY ) VALUES ('" + person.getName() +" ' , " + person.getBirthday() + " )";
    statment.executeUpdate(query);
    getBirthday() returns java.sql.Date object.
    Please, please, help to work it out!

    Thank you, very much.
    I've put the record into DB!!!! Hurray!
    But now I have another problem. I've got a ResultSet & I'd like to extract the DATE from it. But how?
    The Exception text states that the name of the field (Birthday) is incorrect.
    My code:
    Date birthday = resultSet.getDate("Birthday");
    All other fields are perfectly well extracted, but they are Strings.

  • Group by with date range.

    Hi,
    I am looking for effective usage of Group by against date range.
    I have a transaction table as below.
    Date            customer_no      amount_paid
    01-Dec-13     001                  500
    02-Dec-13     001                  360
    09-Dec-13     001                  200
    02-Nov-13     001                  360
    09-Nov-13     001                  200
    02-Nov-13     001                  360
    09-Oct-13     001                  200
    02-Oct-13     001                  360
    09-Oct-13     001                  200
    02-Sep-13     001                  360
    09-Sep-13     001                  200
    ............... etc.
    I would like to see sum(amount_paid) by past date ranges 1-30 days, 31-60 days, 61-90 days.
    Below are expected results.
    Customer          Duration       amount_paid
    001                    1-30             980
    001                    31-60           450
    001                    61-90          1200
    002                    1-30             300
    002                    31-60           490
    002                    61-90           320
    003                    1-30             450
    ......................etc.
    I have to group by customer no and date range (1-30, 31-60, 61-90..etc).
    Can someone help me getting query for this.
    Thanks...
    Sreeram.

    SQL> with t
      2  as
      3  (
      4  select to_date('01-Dec-13', 'dd-Mon-rr') dt, '001' customer_no, 500 amount_paid from dual
      5    union all
      6  select to_date('02-Dec-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
      7    union all
      8  select to_date('09-Dec-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
      9    union all
    10  select to_date('02-Nov-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
    11    union all
    12  select to_date('09-Nov-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
    13    union all
    14  select to_date('02-Nov-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
    15    union all
    16  select to_date('09-Oct-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
    17    union all
    18  select to_date('02-Oct-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
    19    union all
    20  select to_date('09-Oct-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
    21    union all
    22  select to_date('02-Sep-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
    23    union all
    24  select to_date('09-Sep-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
    25  )
    26  select customer_no
    27       , ((grp_val - 1) * 30) + 1 start_val
    28       , grp_val * 30 end_val
    29       , sum(amount_paid) amount_paid
    30    from (
    31            select dt
    32                 , customer_no
    33                 , amount_paid
    34                 , ceil(sum(dt_interval) over(partition by customer_no order by dt)/30) grp_val
    35              from (
    36                      select dt
    37                           , customer_no
    38                           , amount_paid
    39                           , nvl(dt - lag(dt) over(partition by customer_no order by dt), 1) dt_interval
    40                        from t
    41                   )
    42         )
    43   group
    44      by customer_no
    45       , grp_val
    46   order
    47      by grp_val;
    CUS  START_VAL    END_VAL AMOUNT_PAID
    001          1         30         560
    001         31         60         760
    001         61         90         920
    001         91        120        1060
    SQL>

  • Query regarding Min function with Date

    Dear All,
    I have written query as follows but it is giving me error message.
    Selection CityCode, CityName, Min(Date)
    from Entry
    I want to write a query which should generate minimum date of transactions of city. There are about 50 cities in the Entry table and against each city there are thousands of records, I want to display only the oldest date against each city with its code. In the out put there should 50 rows as there are 50 cities and oldest (min) date. Can any one please help on this SQL.
    Thanks

    Do you want just min date in the table or need grouping by citycode and city name also?
    If just min date of the table is needed, use row_number analytic function to get the min date in the table.

  • Keep Group headings with data - control your page breaks

    Trying to keep the group heading with the appropriate transaction information.  Currently, get a group heading at the bottom of a page and then the transactions print on the next page.   Difficult to determine what the transaction information is without the appropriate group headings displayed.   The amount of transaction data is not static, it varies from page to page.  Some of the reports can be close to 100 pages.   Please advise.

    Hi Kim,
    You can use the option u201CNew Page Afteru201D in Section Expert for Group Footer section so that the new group Header will display on the next page.
    Regards,
    Alpana

  • How to check the integer value with Date Column

    Hi Friends,
    I have a filter called 'Days'. I need to show the data based on the Days filter (Example : 2 Days).
    Example Query:
    Select * from Tb1
    Where EndDate(Value as '03/05/2013' > Days ( value as 2)
    How to handle the above scenario.
    Thanks in Advance....
    Regards,
    LuckyAbdul

    what meanings does it make. how can you compare a date to day count. Or is the inetger value an offset ie say 2 days from today etc?
    If yes you can use like below illlustration
    DECLARE @DayOffset int
    SET @DayOffset = 2
    SELECT *
    FROM TAble
    WHERE ENdDate >= DATEADD(dd,DATEDIFF(dd,0,GETDATE()),@DayOffset+1)
    refer
    http://visakhm.blogspot.in/2010/01/some-quick-tips-for-date-formating.html
    Please clarify with an example what you're expecting if its different from the above.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • CAML Query returning all items with date condition

    HI,
    I have a problem doing a query with CAML over the elements of a calendar in SharePoint 2013
    I just want to retrieve all items, which have been modified on a particular date. But below query returns all items from the Calendar.
    Any suggestion how to get specific items from the calendar. The same issue exists for start date  and end date.
      var oWebsite = clientContext.get_web();
        this.collList = oWebsite.get_lists();
        var camlQuery1 = new SP.CamlQuery();
       camlQuery1.set_viewXml(
       '<query><Where>'+
          '<Eq>'+
             '<FieldRef Name=\'Modified\'  IncludeTimeValue=\'TRUE\'/>' +
             '<Value Type=\'DateTime\'>2014-02-24T12:00:00Z</Value>'+
          '</Eq>'+
       '</Where></query>');
        this.collListItem1 = oList.getItems(camlQuery1);
        clientContext.load(collListItem1);

    Firstly try to make this change in your query and see if that helps
    camlQuery1.set_viewXml(
    '<View><Query><Where>'+
    '<Eq>'+
    '<FieldRef Name=\'Modified\' IncludeTimeValue=\'TRUE\'/>' +
    '<Value Type=\'DateTime\'>2014-02-24T12:00:00Z</Value>'+
    '</Eq>'+
    '</Where></Query></View>');
    Geetanjali Arora | My blogs |

  • Append value with Data Storage Vis

    Dear,
    I would like to use the Data Storage VIs to collect my data but I can't achieve my target.
    I'm acquiring 1000 samples at 1kHz (N samples on demand) and I make the mean value of the samples. At the end of this proces I have a scalar value and the initial time at wich I have acquired the data. With this two I build a waveform and then I use the Write Data Storage Vi (TDMS) with "append" write mode to save my data.
    When I read the Data Storage all the value have lost the time information. They start from 1.00.00,000 01/01/1904 and are equal spaced in time.
    How can I keep the time information?
    Thanks

    Sorry totaly misread what you were doing.
    You need to create ensure that waverform that is saved has the correct values for X0 and dx when you save it. Use the build waveform function to acheive this.
    edit:
    the default value for X0 is timestamp 0 (1904), use get datetimestamp at the very start of the cycle to get the correct value.
    James
    Message Edited by James W on 04-21-2010 01:06 PM

  • Unable to create table with column default value with date interval

    Please help to create table with calculated date defaullt value:
    CREATE TABLE emp (
      birth_date  DATE  DEFAULT sysdate + interval '3' day NOT NULL
    or
    CREATE TABLE emp (
      some_date DATE,
      birth_date  DATE  DEFAULT some_date NOT NULL
    or
    CREATE TABLE emp (
      some_date DATE,
      birth_date  DATE  DEFAULT some_date + interval '3' day NOT NULL
    below syntax error:
    TT1001: Syntax error in SQL statement before or at: "+"

    I'm afraid this is not possible; as per the SQL Reference, TimesTen only supports 'constant expressions' for the DEFAULT clause and none of these are constant expressions.
    Chris

  • Dimention values with date range

    Hi All
    We have a requirement to have dimensions which have date ranges like
    today's
    yesterdays
    last week
    last month etc
    When tried to add dimension I can see only string integer and float values
    Do anybody knows how to add Date with the range??
    TIA
    Lalit

    The solution we've worked with in the past is to convert the dates to YYYYMMDD and store in the index as Integer values. Thus you can use range filters by converting any incoming values to the same format. Your interface layer will have to written to accommodate those mappings.

  • Group by with date

    Hi !
    I need help (sorry for my english) :
    my sql :
    SELECT ligne,TO_CHAR(TO_DATE(DATE_VAL),'DD/MM/YYYY') DATE_VAL,COUNT(*)
    FROM VALID, MIS, SERV
    WHERE     id_mis=id_mis_val AND id_serv=id_serv_vmis
    AND DATE_VAL >= '04/06/2007' AND DATE_VAL < '06/06/2007'
    AND LIGNE_VSERV = 923
    GROUP BY date_val
    the result :
    900 04/06/2007 1
    900 04/06/2007 2
    900 04/06/2007 1
    900 04/06/2007 1
    900 04/06/2007 1
    900 05/06/2007 1
    WHY ?
    I want the result like that :
    900 04/06/2007 6
    900 05/06/2007 1
    How to make that ? please help!
    Thanks a lot

    Why not...?
    SQL>  create table t(c1 date,cnt number);
    Table created.
    SQL> insert into t
      2  values(sysdate,10);
    1 row created.
    SQL> insert into t
      2  values(sysdate,15);
    1 row created.
    SQL> insert into t
      2  values(sysdate-12,15);
    1 row created.
    SQL> insert into t
      2  values(sysdate-12,15);
    1 row created.
    SQL> select to_char(c1,'ddmmyyyy') c1,sum(cnt) sm
      2  from t
      3  group by to_char(c1,'ddmmyyyy');
    C1               SM                                                            
    02062007         30                                                            
    14062007         25
    Message was edited by:
            jeneesh
    Forgot to refresh...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Converting Oracle query to Sql Server with date manipulation

    The following SSIS statement works great in Oracle, and it parses successfully in the "Sql Task" window. In Oracle it returns
    this result:
    FROM_DT              THRU_DT
    16-Jan-2014      23-Jan-2014
    select
    case
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then to_date('24'||to_char(add_months(sysdate,-1),'mmyyyy'),'ddmmyyyy')
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('01'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('08'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    else to_date('16'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    end as from_dt,
    case
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then trunc(last_day(add_months(sysdate,-1)))
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('07'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('15'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    else to_date('23'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    end as thru_dt
    from sys.dual
    How can I convert this to Sql Server ?

    >>You mean you get the data from Oracle and tries to insert it into SQL Server?
    - no, sorry, I want to convert the syntax to Sql Server
    >>Are
    you running the query in OLEDB provider connected to the Oracle's database?
    - yes, this works fine now (after fixing this redundancy:
    to_char(to_date(sysdate,'dd-mon-yyyy'),'dd')change toto_char(sysdate,'dd')

  • Purchasing Group Relation with data or setting

    Dear All,
    Can anyone please advice me if there is anything we should check after new purchasing group have been created?
    I have just created 15 new purchasing group, some of the group code is being replaced by this new group code.
    Thank you very much,
    Regards,
    Chee Wee

    Hi
    If you are creating a new purchaing group then it is not at all a problem because it is a free floating entity. You don't have to assign to any other entity. But if you are deleting any then you need to consider previous transaction in which that purchasing group is used. If there is any open transaction then in that you need to give new purchasing group. Then reports for old transaction may also give inconsistancy.
    Regards
    Antony

  • Crosstab Query re Grouping Data into Value Ranges

    Hi
    I am trying to analyse some data in a Crosstab & have a query re grouping.
    The data contains sales transaction info such as selling price, quantity etc. I would like to create a grouping in the Crosstab based on a sale price range (eg £0 - £10, £10 - £20 etc) so that I can show the total quantity sold in each price range.
    To date my method has been to create a formula with Select Case which identifies each transaction into a price range. I would then use this formula in my Crosstab. The main issue with this method is that there will be a large number of Cases & the possibility this will need to be added to / modified going forward.
    Whilst I think this will work I am hoping there is better method to follow?
    Thanks
    Jon

    Hi Jamie,
    Thank you for your help.
    I'm looking to group in increments of 10 so it looks like the Floor function will do the trick, thank you.
    I'll probably use an If statement to do a "block" of prices at either end of the scale (ie < 100 then 100, > 1000 then 1000+ else Floor ({Sales Field},10). Hopefully this way I'll reduce the overall no of rows.
    Thanks again for your help.
    Jon

Maybe you are looking for

  • Linking Endnote X4 with WORD 2011 for mac.

    My Endnote X4 software does not show up in my toolbar of WORD 2011. How do I tackle this problem?

  • SAP Inbound Proxy Error

    Hi Experts, I am facing an issue when executing inbound proxy message. After the message completed, the message status end up with Error. The error says below details. "Information about the method parameters is missing for the interface INTERFACE_NA

  • Web pages won't adjust automatically to the width of my browser.

    MS IE will automatically adjust the web page to the size of the browser. But Firefox doesn't do this, so I have to scroll left and right. Can this be fixed? == This happened == Every time Firefox opened

  • I just bought a macbook air and I can't open any of my downloaded apps in itunes

    I just bought a macbook air and I can't open any of my downloaded apps in itunes. They also keep trying to download to my iphone 4 s but only half of them will download, the others say waiting. thanks.

  • List of sales order without order bom fix

    dear sir we are using variant configuration with result oriented order bom fix in cu51/cu52 we want the list of sales orders for which order bom is not created using cu51/cu52 fixing can any body tell me where this information is available? thanking