How to view data based on range

Discussion in 'MySQL' started by Tintumol, Dec 13, 2010.

  1. #1
    hi everyone.

    I would like to ask on how to view data based on specific range.
    I have many data in dbase. example:

    Year Sales
    2000 8976
    2001 2345
    2002 3324
    2003 2223
    2004 2234
    2005 1123
    2006 5563
    ........
    .....
    .....
    ....
    2011 3345
    ......
    ....
    ...

    but, what should i do if i just want to display data only last 5years? even i access the system during any years in future.?
    can someone help me plizz..
     
    Tintumol, Dec 13, 2010 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Here is the query
    SELECT Sales from table_name WHERE `Year` >= ( YEAR(NOW()) - 5 )
    Code (markup):
     
    mwasif, Dec 13, 2010 IP
  3. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Yes that will help. You can add additional constraints to fit your requirement
     
    iama_gamer, Dec 14, 2010 IP