This discussion is archived
1 Reply Latest reply: Oct 12, 2012 2:38 PM by rp0428 RSS

sql query issue

928518 Newbie
Currently Being Moderated
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.
  • 1. Re: sql query issue
    rp0428 Guru
    Currently Being Moderated
    Not a JDBC related question.

    You should post this in a mySQL forum.
    http://forums.mysql.com/list.php?61
    >
    I want the value inside 'success_count' against individual 'brand_code', which lie within the last 7 days from the current date.
    . . .
    >
    It is not clear why you would only get the two rows you want when there are other rows that 'lie within the last 7 days'.

    Please mark this thread ANSWERED and repost in an appropriate forum.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points