This topic is locked

Query a date range

6/5/2008 12:15:17 PM
PHPRunner General questions
L
ld_ski author

Hi, being brand new to mysql I don't know how to create a date query - instead of showing all the records in the database, I'd like help to:

  1. do a summary of all txns by month etc - what's the syntax for this?
  2. specify a particular month in the query (eg June 2008).
  3. specify a date range in the table (eg. Jan - Mar 2008)
    How can I do this please?
    Many Thanks

J
Jane 6/6/2008

Hi,
see my aswers below:

  1. use aggregate function in the SQL query:
    select field1,

    sum(field2) as sum_field2

    from TableName

    order by field1


2, 3. use date functions and BETWEEN in the where clause of your query:

http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html

http://www.webcheatsheet.com/sql/interacti...sql_between.php