Results 1 to 2 of 2

Thread: date...

  1. #1
    Join Date
    Jan 2005
    Posts
    14

    Unanswered: date...

    hi all,

    I want to know how to select with a condition only on month and year. For example, the total cost on December 2004?

    select sum(cost)
    from visit
    where v_date = "2003-12"; Is this correct?


    Thank you very much.
    Last edited by roustabout; 02-01-05 at 06:54.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you can take one of two approaches

    the simple approach --

    ... where month(v_date) = 12 and year(v_date) = 2003

    the efficient approach --

    ... where v_date between '2003-12-01' and '2003-12-31'

    the second is preferred because it allows the database to utilize an index on v_date
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •