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.

Similar Messages

  • How to use aggregate function with Date

    Hi All,
    I have a group of date from that is it possible to Max and Min of date.
    I have tried like this but its errored out <?MIN (current-group()/CREATION_DATE)?>.
    I have also tried like this but it doesnt works
    <?xdoxslt:minimum(CREATION_DATE)?>
    Is it possible to use aggregate function with date values.
    Thanks & Regards
    Srikkanth

    Hi KAVI PRIYA,
    if date is not in cannonical format, how can we change it in BI publisher, then how to calcualte minimum and as well as maximum.
    please advise me,
    Thanks,
    Sri

  • A query regarding synchronised functions, using shared object

    Hi all.
    I have this little query, regarding the functions that are synchronised, based on accessing the lock to the object, which is being used for synchronizing.
    Ok, I will clear myself with the following example :
    class First
    int a;
    static int b;
    public void func_one()
    synchronized((Integer) a)
    { // function logic
    } // End of func_one
    public void func_two()
    synchronized((Integer) b)
    { / function logic
    } // End of func_two
    public static void func_three()
    synchronized((Integer) a)
    { // function logic
    } // End of func_three, WHICH IS ACTUALLY NOT ALLOWED,
    // just written here for completeness.
    public static void func_four()
    synchronized((Integer) b)
    { / function logic
    } // End of func_four
    First obj1 = new First();
    First obj2 = new First();
    Note that the four functions are different on the following criteria :
    a) Whether the function is static or non-static.
    b) Whether the object on which synchronization is based is a static, or a non-static member of the class.
    Now, first my-thoughts; kindly correct me if I am wrong :
    a) In case 1, we have a non-static function, synchronized on a non-static object. Thus, effectively, there is no-synchronisation, since in case obj1 and obj2 happen to call the func_one at the same time, obj1 will obtain lock for obj1.a; and obj2 will obtain lock to obj2.a; and both can go inside the supposed-to-be-synchronized-function-but-actually-is-not merrily.
    Kindly correct me I am wrong anywhere in the above.
    b) In case 2, we have a non-static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a. However, since obj1.a and obj2.a are the same, thus we will indeed obtain sychronisation.
    Kindly correct me I am wrong anywhere in the above.
    c) In case 3, we have a static function , synchronized on a non-static object. However, Java does not allow functions of this type, so we may safely move forward.
    d) In case 4, we have a static function, synchronized on a static object.
    Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a. However, since obj1.a and obj2.a are the same, thus we will indeed obtain sychronisation. But we are only partly done for this case.
    First, Kindly correct me I am wrong anywhere in the above.
    Now, I have a query : what happens if the call is made in a classically static manner, i.e. using the statement "First.func_four;".
    Another query : so far we have been assuming that the only objects contending for the synchronized function are obj1, and obj2, in a single thread. Now, consider this, suppose we have the same reference obj1, in two threads, and the call "obj1.func_four;" happens to occur at the same time from each of these threads. Thus, we have obj1 rying to obtain lock for obj1.a; and again obj1 trying to obtain lock for obj1.a, which are the same locks. So, if obj1.a of the first thread obtains the lock, then it will enter the function no-doubt, but the call from the second thread will also succeed. Thus, effectively, our synchronisation is broken.
    Or am I being dumb ?
    Looking forward to replies..
    Ashutosh

    a) In case 1, we have a non-static function, synchronized on a non-static object. Thus, effectively, there is no-synchronisationThere is no synchronization between distinct First objects, but that's what you specified. Apart from the coding bug noted below, there would be synchronization between different threads using the same instance of First.
    b) In case 2, we have a non-static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a.obj1/2 don't call methods or try to obtain locks. The two different threads do that. And you mean First.b, not obj1.b and obj2.b, but see also below.
    d) In case 4, we have a static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a.Again, obj1/2 don't call methods or try to obtain locks. The two different threads do that. And again, you mean First.b. obj1.b and obj2.b are the same as First.b. Does that make it clearer?
    Now, I have a query : what happens if the call is made in a classically static manner, i.e. using the statement "First.func_four;".That's what happens in any case whether you write obj1.func_four(), obj2.func)four(), or First.func_four(). All these are identical when func_four(0 is static.
    Now, consider this, suppose we have the same reference obj1, in two threads, and the call "obj1.func_four;" happens to occur at the same time from each of these threads. Thus, we have obj1 rying to obtain lock for obj1.aNo we don't, we have a thread trying to obtain the lock on First.b.
    and again obj1 trying to obtain lock for obj1.aYou mean obj2 and First.b, but obj2 doesn't obtain the lock, the thread does.
    which are the same locks. So, if obj1.a of the first thread obtains the lock, then it will enter the function no-doubt, but the call from the second thread will also succeed.Of course it won't. Your reasoning here makes zero sense..Once First.b is locked it is locked. End of story.
    Thus, effectively, our synchronisation is broken.No it isn't. The second thread will wait on the same First.b object that the first thread has locked.
    However in any case you have a much bigger problem here. You're autoboxing your local 'int' variable to a possibly brand-new Integer object every call, so there may be no synchronization at all.
    You need:
    Object a = new Object();
    static Object b = new Object();

  • How to use TRUNC function with dates in Expression Builder in OBIEE.

    Hi There,
    How to use TRUNC function with dates in Expression Builder in OBIEE.
    TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
    Thanks in advance

    use this instead:
    TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE)

  • How to execute a function with date parameter as an input?

    HI
    I have a function named fun1(v_fun in date), with date as an input parameter and it returns a number. I have created the function successfully. But i couldnt execute this function in sqlplus. How to pass the dates? Can any one help me in this regard.

    Hi,
    V11081985 wrote:
    HI
    I have a function named fun1(v_fun in date), with date as an input parameter and it returns a number. I have created the function successfully. But i couldnt execute this function in sqlplus. It's hard for me to say what you're doing wrong when I don't know what you're doing. Post a complete test script that people can run to re-create the problem and test their ideas. Include a function definition, CREATE TABLE and INSERT statements for any of your own tables (if necessary), and the results you want to get from that data, as well as your query.
    How to pass the dates? Can any one help me in this regard.You can call the function like this:
    SELECT  fun1 (hiredate)  AS fun1_results
    FROM    scott.emp
    ;

  • 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.

  • Trunc function with date

    when i use in my proceadure where trunc(timesent_acct) between '30-AUG-2006' and '27-SEP-2006' it returns 410 rows
    but
    when i use where timesent_acct between '30-AUG-2006' and '27-SEP-2006' it returns me 400 rows
    what actually happened out there my data stored in timestamp like this '9/27/2006 10:24:18 AM'
    what trunc actually do with dates
    thanks

    Hello,
    Trunc() without parameter retire the hour part of a date.
    SQL> alter session set nls_date_format='DD/MM/YYYY HH24:MI:SS'
      2  /
    Session modifiée.
    SQL> select sysdate, trunc(sysdate) from dual
      2  /
    SYSDATE             TRUNC(SYSDATE)
    07/11/2006 14:51:04 07/11/2006 00:00:00
    SQL> Francois

  • Query with scalar valued function with date filter

    Hello experts
    i have a problem by filtering my results with the date
    i have written the following code
    SELECT
    T1.ItemCode
    , T1.Dscription
    ,DBO.F_CALCULATION_QUANTITY(T1.ITEMCODE)
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    (T0.DOCDATE BETWEEN '2010-11-01' AND '2010-11-30')
    and (t2.cardcode ='80022')
    and (T0.CANCELED= 'N')
    group by  t1.itemcode, T1.Dscription, t2.suppcatnum
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
    (@ITEMCODE AS NVARCHAR(10))
    RETURNS
    NUMERIC(19,2)
    AS
    BEGIN
    DECLARE
    @RESULT1 AS NUMERIC(19,2),
    @RESULT2 AS NUMERIC(19,2),
    @RESULT AS NUMERIC(19,2)
    SELECT @RESULT1=SUM(A.QUANTITY)
    FROM INV1 A
    JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN  '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
    SELECT @RESULT2=SUM(A.QUANTITY)
    FROM RIN1 A
    JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
    SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
    --SELECT @RESULT=@RESULT1- @RESULT2
    RETURN @RESULT
    END
    the problem i have is that i want to filter my results accoring to the date provided by the user. i want it to be dynamic query.
    by now, what i do is to edit the docdate in the function in order to get the desired results. this is not what i want.
    could you please help me on this way in order to let the user to input the date?if i add the [%] in the query, it does not bring me the right results

    i have already edited the function to
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
    (@ITEMCODE AS NVARCHAR(10),
    @STARTDATE1 as DATETIME,
    @ENDDATE1 AS DATETIME
    RETURNS
    NUMERIC(19,2)
    AS
    BEGIN
    DECLARE
    @RESULT1 AS NUMERIC(19,2),
    @RESULT2 AS NUMERIC(19,2),
    @RESULT AS NUMERIC(19,2)
    SELECT @RESULT1=SUM(A.QUANTITY)
    FROM INV1 A
    JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
    SELECT @RESULT2=SUM(A.QUANTITY)
    FROM RIN1 A
    JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
    SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
    RETURN @RESULT
    END
    could you please how to edit the query as well?
    i have added the following code and it comes up with the right itemcode but the quantity does not work
    DECLARE
    @ITEMCODE AS NVARCHAR(10),
    @STARTDATE1 as DATETIME,
    @ENDDATE1 AS DATETIME
    SET @STARTDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-01')
    set @ENDDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-30')
    SELECT
    T1.ItemCode
    , T1.Dscription
    ,DBO.F_CALCULATION_QUANTITY(@ITEMCODE,@STARTDATE1,@ENDDATE1)
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    (T0.DOCDATE BETWEEN @STARTDATE1 AND @ENDDATE1)
    and  (t2.cardcode ='80022')
    and (T0.CANCELED= 'N')
    group by  t1.itemcode, T1.Dscription, t2.suppcatnum
    the result is this
    70200     alert1     0.00
    70210     alert2     0.00
    70220     alert3     0.00
    70230     alert4     0.00
    as you can see the quantity is 0 and it shouldnt be
    Edited by: Fasolis Vasilios on Oct 31, 2011 10:49 AM

  • Query regarding XI interaction with database

    Hi all,
    I have got the Oracle database and SAP R/3 system
    Is it possible that through JDBC adapter ,
    a) Direct fetching of data from database
    b) Data should come in XI and after mapping should be  
        posted in SAP R/3 .i.e complete automated process
    c) Is it possible to put direct query statement in XI
        while connection with database through JDBC adapter
        E.g For fetching the vendor data from database
        Select * from .... 
    Thanks in advance
    Shikha Jain

    Shikha,
    <i>a) Direct fetching of data from database</i>
    In the JDBC Sender adapter you have to mention the SQL Query.
    <i>b) Data should come in XI and after mapping should be
    posted in SAP R/3 .i.e complete automated process</i>
    This is what XI does. There is no manual intervention needed.
    <i>c) Is it possible to put direct query statement in XI
    while connection with database through JDBC adapter
    E.g For fetching the vendor data from database
    Select * from ....</i>
    your question a is same. You can execute a SQL statement in the Adapter which polls the database in the intervals you mention. It could be a SELECT or EXEC PROC etc.
    regards
    Shravan

  • Query regarding sys_context function

    Hello
    I have created report with custom folder and parameters are passed using sys_context function. I have few queries regarding this.
    1) How to see actual sql query executed by report. I can see from discover administorator - sql inspector. But it is not showing which is value passed for sys_context parameter. If want to see query with full parameter then what to do? I have also tried to look it from toad - session browser, there also it is not showing parameter value.
    2) If anything special needed to manage sys_context variable. i.e i have executed report with parameter 1 = A and now next time executed with parameter 1 =b. Will it takes proper value, i mean sys_context parameter will be refreshed itself, or need to do somehting..
    Please help me out.
    Thanks in advance

    Hi,
    How to see actual sql query executed by reportSYS_CONTEXT returns values from a namespace. Normally you create a local namespace and values in this namespace can only be retrieved by the session. So there is no way to see the values for a Discoverer session from Toad. Normally, one would create a Discoverer report that returns all the values in your namespace that you can use for debugging.
    If anything special needed to manage sys_context variableNo, once you have set the context in the namespace using DBMS_SESSION.set_context then it is there for the rest of the session.
    Rod West

  • How to use MAX() function with date field

    Hi Frzz,
    I have created a Graphical calculation view in which i have multiple records for each employee with different dates. But my requirement is to take the records which have maximum date.
    I have converted the date into Integer and applied the MAX() function. But still am getting multiple records.
    Is there is any other way we can achieve this requirement in Graphical Calculation view??  Your suggestion will really help me.
    Thank  you.
    Krishna.

    Hmm... what have you tried out so far?
    Look, I took the effort and created a little example, just for you
    Assume we have a table that contains the logon dates of users.
    Every line contains the logon date and some info on the user.
    Very much like a not-normalized log file could look like.
    Now, the output we want is: one line per user with the most current logon time.
    Not too difficult:
    1. Have a aggregation node that gives you the distinct user details - one line for every user:
    2. Have another aggregation node that gives you the last (MAX) logon date per user:
    Finally you do a 1:1 join on the USER_ID and map the result to the output.
    Easy as pie
    - Lars

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Query regarding oracle functions

    Hi All,
    I ahve been trying to work with decode and NVL to get the following output:
    Value     Output
    NULL     1
    0     1
    1     1
    2     2
    3     3
    for this i have written the below query:
    SELECT DECODE(NVL(high_value,1),0,1,NVL(high_value,1)) from tab1;
    Can there be any alternate to this using other functions?
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Thanks
    Nikhil

    Use CASE
    with t_data as
    select null as val from dual union all
    select 0 from dual union all
    select 1 from dual union all
    select 2 from dual union all
    select 3 from dual
    SELECT
         val,
         CASE
              WHEN  (val IS NULL ) OR ( val    = 0 )
              THEN
                   1
              ELSE
                   val
         END AS output
    FROM
         t_data;
    VAL                    OUTPUT                
                           1                     
    0                      1                     
    1                      1                     
    2                      2                     
    3                      3                     

  • 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 |

  • Query regarding transport of customizing data to another client

    I have some queries related to transport of workbench and Customizing data to another client. As I am new to SDN forum, I am not sure if this is the right forum to post my query. Kindly let me know.

    Frankly, I wasn't even aware of the "Software Logistics" subforum for Netweaver. It is not frequented much, but seems to be the perfect home for questions about the CTS (that are not related to ABAP development at the same time, e.g. object dependencies).
    So, thank you too
    Thomas

Maybe you are looking for

  • The big iChat problems. Audio/Video (now completely broken in 10.7.3), the "not-authorized" problem

    So, I am running iChat on OS X Lion 10.7.3 on an early-2011 MBP 13'' . These problems have been here for a while, though (I got my comp with 10.7.0). I have AIM/GMail/Yahoo connected.. One problem is the issue of non-authorized people. There is a lis

  • Sequential Count of rows in a Column

    Hi, In a query, I have a table defined with the relevant detail required by the business. I need to insert a count into the first column so it identifies a unique number. e.g. row 1 = 1, row 2 = 2 etc. How can this be done?

  • Disable Print for specific situations

    I Use Adobe Pro X. Is there a way to make a form not print if certain information is entered?  For instance, some forms in our list are for specific clients only. If a user pulls up a form with the incorrect client, I want to add a script that disabl

  • Macbook with student discount

    I've just finished my A levels and will almost certainly be starting university in october. The question is, do I have to wait till then if I want to get myself a student discount? Cheers, sd

  • Get Info dialog is broken

    When i try to start «Get Info» dialog, i can see this picture: http://image.bayimg.com/gadbfaadm.jpg (or http://bayimg.com/gaDbFAADm ) (all field is moved to right bottom corner behind a border) Windows 7 64 bit Ultimate iTunes 10.1.2.17 (but in prev