Loading ...
Sorry, an error occurred while loading the content.
 

RE: [php-objects] Please help with a SQL Query

Expand Messages
  • Ankit Mathur
    Hi Friends, First of all I m sorry for not being able to reply since my last message. However, coming back to my query. 1. No. I don t want MAX of the amount
    Message 1 of 11 , Jan 31, 2008
      Hi Friends, First of all I'm sorry for not being able to reply since my last message. However, coming back to my query. 1. No. I don't want MAX of the amount for each account but the latest entry even though it could be lesser than earlier amounts. 2. I read in a mail where I was asked to supply other columns also. Here's the list:Id, AcctId, RechargeDate, AmtBeforeRecharge, AmtAfterRecharge, RechargeAmt, RechargeType, RechargedByNow to again put my query in front of you guys.
      I want only the latest entry of distinct accountids & not the rest of the records
      Basically, records having MAX(RechargeDate) but one record only for one AccountId.
      I hope fellow members can help now.

      Ankit Mathur


      To: php-objects@yahoogroups.comFrom: cgrp@...: Mon, 28 Jan 2008 20:19:04 +0100Subject: Re: [php-objects] Please help with a SQL Query



      In message <C2C319C4C1CC7D46B2D7815BE3A2753E03CEC6B3@...>, Atkinson, Robert <ratkinson@...> writes>I read it as he wants the highest (MAX) amount from each account?>>Rob.Well, I didn't <G>Perhaps, if (s)he is still around, maybe (s)he will let us know.-- Pete ClarkSunny Andaluciahttp://hotcosta.com/Andalucia.Spain






      _________________________________________________________________
      Post ads for free - to sell, rent or even buy.www.yello.in
      http://ss1.richmedia.in/recurl.asp?pid=186

      [Non-text portions of this message have been removed]
    • Abdullah Al Masud
      Hi Mathur The simplest way (but may not be efficient w.r.to memory!!) is to add a new column in the table, e.g. addTrack (initially 1 for the first entry to
      Message 2 of 11 , Feb 1, 2008
        Hi Mathur

        The simplest way (but may not be efficient w.r.to memory!!) is to add a new column in the table, e.g. addTrack (initially 1 for the first entry to the table). It will increase by 1 every time you add a record. So, the last record will have the highest (or MAX) value for addTrack. Hope it will work. There several other ways to do it. But this is the simplest with a very low increase in memory (but still uses memory!!). There may be tricks to do it without extra column if you could define the Id to stick to the increment rule in anyway. MAX(recheargeDate) will not work when in the same date you have many entries (at least 2). You may add recheargeTime also, then you can work with both the date and time. But it may require some logical coding!

        Best wish.
        Masud


        ----- Original Message ----
        From: Ankit Mathur <ankitmathur82@...>
        To: php-objects@yahoogroups.com
        Sent: Friday, February 1, 2008 2:48:18 PM
        Subject: RE: [php-objects] Please help with a SQL Query

        Hi Friends, First of all I'm sorry for not being able to reply since my last message. However, coming back to my query. 1. No. I don't want MAX of the amount for each account but the latest entry even though it could be lesser than earlier amounts. 2. I read in a mail where I was asked to supply other columns also. Here's the list:Id, AcctId, RechargeDate, AmtBeforeRecharge, AmtAfterRecharge, RechargeAmt, RechargeType, RechargedByNow to again put my query in front of you guys.
        I want only the latest entry of distinct accountids & not the rest of the records
        Basically, records having MAX(RechargeDate) but one record only for one AccountId.
        I hope fellow members can help now.

        Ankit Mathur

        To: php-objects@ yahoogroups. comFrom: cgrp@hotcosta. comDate: Mon, 28 Jan 2008 20:19:04 +0100Subject: Re: [php-objects] Please help with a SQL Query

        In message <C2C319C4C1CC7D46B2D 7815BE3A2753E03C EC6B3@coxsrv- 3.uk.randomhouse .com>, Atkinson, Robert <ratkinson@tbs- ltd.co.uk> writes>I read it as he wants the highest (MAX) amount from each account?>>Rob. Well, I didn't <G>Perhaps, if (s)he is still around, maybe (s)he will let us know.-- Pete ClarkSunny Andaluciahttp: //hotcosta. com/Andalucia. Spain

        ____________ _________ _________ _________ _________ _________ _
        Post ads for free - to sell, rent or even buy.www.yello. in
        http://ss1.richmedi a.in/recurl. asp?pid=186

        [Non-text portions of this message have been removed]





        ____________________________________________________________________________________
        Be a better friend, newshound, and
        know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


        [Non-text portions of this message have been removed]
      • Atkinson, Robert
        Still sounds like you need DISTINCT(accntid) and MAX(rechargedate) to me :- SELECT
        Message 3 of 11 , Feb 1, 2008
          Still sounds like you need DISTINCT(accntid) and MAX(rechargedate) to me :-

          SELECT
          DISTINCT(accntid),RechargeDate,AmtBeforeRecharge,AmtAfterRecharge,RechargeAmt
          ,RechargeType, RechargedByNow, maxdate
          FROM tablename
          WHERE
          maxdate = (SELECT MAX(RechargeDate) FROM tablename WHERE accntid = accntid)
          ORDER BY accntid,RechargeDate

          Not sure if this is exactly right, but should be close.

          Rob.

          -----Original Message-----
          From: php-objects@yahoogroups.com [mailto:php-objects@yahoogroups.com] On
          Behalf Of Ankit Mathur
          Sent: 01 February 2008 07:48
          To: php-objects@yahoogroups.com
          Subject: RE: [php-objects] Please help with a SQL Query

          Hi Friends, First of all I'm sorry for not being able to reply since my last
          message. However, coming back to my query. 1. No. I don't want MAX of the
          amount for each account but the latest entry even though it could be lesser
          than earlier amounts. 2. I read in a mail where I was asked to supply other
          columns also. Here's the list:Id, AcctId, RechargeDate, AmtBeforeRecharge,
          AmtAfterRecharge, RechargeAmt, RechargeType, RechargedByNow to again put my
          query in front of you guys.
          I want only the latest entry of distinct accountids & not the rest of the
          records
          Basically, records having MAX(RechargeDate) but one record only for one
          AccountId.
          I hope fellow members can help now.

          Ankit Mathur


          To: php-objects@yahoogroups.comFrom: cgrp@...: Mon, 28 Jan 2008
          20:19:04 +0100Subject: Re: [php-objects] Please help with a SQL Query



          In message
          <C2C319C4C1CC7D46B2D7815BE3A2753E03CEC6B3@...>,
          Atkinson, Robert <ratkinson@...> writes>I read it as he wants the
          highest (MAX) amount from each account?>>Rob.Well, I didn't <G>Perhaps, if
          (s)he is still around, maybe (s)he will let us know.-- Pete ClarkSunny
          Andaluciahttp://hotcosta.com/Andalucia.Spain






          _________________________________________________________________
          Post ads for free - to sell, rent or even buy.www.yello.in
          http://ss1.richmedia.in/recurl.asp?pid=186

          [Non-text portions of this message have been removed]



          Are you looking for a PHP job? Join the PHP Professionals directory Now!
          http://www.phpclasses.org/professionals/
          Yahoo! Groups Links




          ***********************************************************************************
          Any opinions expressed in email are those of the individual and not necessarily those of the company. This email and any files transmitted with it are confidential and solely for the use of the intended recipient
          or entity to whom they are addressed. It may contain material protected by attorney-client privilege. If you are not the intended recipient, or a person responsible for delivering to the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited.

          Random House Group + 44 (0) 20 7840 8400
          http://www.randomhouse.co.uk
          http://www.booksattransworld.co.uk
          http://www.kidsatrandomhouse.co.uk
          Generic email address - enquiries@...

          Name & Registered Office:
          THE RANDOM HOUSE GROUP LIMITED
          20 VAUXHALL BRIDGE ROAD
          LONDON
          SW1V 2SA
          Random House Group Ltd is registered in the United Kingdom with company No. 00954009, VAT number 102838980
          ***********************************************************************************
        Your message has been successfully submitted and would be delivered to recipients shortly.