How To build MySql Query to Get Call History From Database!

Discussion in 'MySQL' started by zer0_c0d3r, Apr 4, 2012.

  1. #1
    Hi all expertz,
    I am newly hire intern in web development field and my senior ask me to build mysql query to draw out call history from database.

    They want me to build query to get call record of:
    1- Today
    2- Yesterday
    3- Last Week
    4- this week


    Just give me sample code or give me hint. we are working on mobile billing app. Please help me it is very necessary for me because i am a fresh intern. Thanks
     
    zer0_c0d3r, Apr 4, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    I would use 4 individual queries to pull the records based on the dates. It's possibly, but would be very complex and probably much slower to try and pull that data in a single query.
     
    jestep, Apr 5, 2012 IP
  3. zer0_c0d3r

    zer0_c0d3r Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    can you post 4 individual queries jestep..??
     
    zer0_c0d3r, Apr 5, 2012 IP
  4. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Today:
    SELECT * from `table` where DATE(`datefield`) = DATE(NOW())
    Code (markup):
    Yesterday:
    SELECT * from `table` where DATE(`datefield`)  = DATE(NOW()) - INTERVAL 1 DAY
    Code (markup):
    This week:
    SELECT * from `table` where WEEK(`datefield`) = WEEK(NOW())
    Code (markup):
    Last week:
    SELECT * from `table` where WEEK(`datefield`) = WEEK(NOW()) - 1
    Code (markup):
     
    superdav42, Apr 7, 2012 IP