Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql query issue

Status
Not open for further replies.

buttsp

MIS
Oct 12, 2012
1
DE
Hi all,
I am finding it difficult to build one mysql query.

I have a table messages_stats_analysis_ota, with 4 columns: [brand_code, date_time_from, date_time_to, success_count].

I want the value inside 'success_count' against individual 'brand_code', which lie within the last 7 days from the current date.

u2, 01.10.2012, 07.10.2012, 100
u2, 02.10.2012, 08.10.2012, 100
u2, 03.10.2012, 07.10.2012, 100
u2, 08.10.2012, 14.10.2012, 50
fr, 01.10.2012, 07.10.2012, 200


Now lets assume, the current date is 08.10.2012.

I want only the follwoing 2 rows to be retrieved:

u2, 01.10.2012, 07.10.2012, 100
fr, 01.10.2012, 07.10.2012, 200

I tried to build this query:

SELECT * FROM messages_stats_analysis_ota WHERE date_time_from >= DATE_SUB(CURDATE(), INTERVAL 7 DAY);

but it gives me, the follwoing, which i dont want:

u2, 01.10.2012, 07.10.2012, 100
u2, 02.10.2012, 08.10.2012, 100
u2, 03.10.2012, 07.10.2012, 100
fr, 01.10.2012, 07.10.2012, 200

Assumtpion is current date is: 08.10.2012.

Coudl someone please help me out?

Thanks.
 
Code:
WHERE date_time_from >= CURRENT_DATE - INTERVAL 7 DAY -- 1st range test low end
  AND date_time_from  < CURRENT_DATE - INTERVAL 6 DAY -- 1st range test high end
  AND date_time_to >= CURRENT_DATE - INTERVAL 1 DAY  -- 2nd range test low end 
  AND date_time_to  < CURRENT_DATE                   -- 2nd range test high end

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top