alohaaaron
Programmer
Hi, I have the query below with the data and query below. I want to select dates from Intable that are with a one month range of the Outtable dates and group them. That works fine
But I also want to select values within the data ranges where valuein=valueout. Thanks in advance, Aaron
The end result should read.
dateout-----total--mymatch
2009-01-05 5 2
2009-03-01 4 3
2009-04-01 4 3
instead of this which the query below produces.
dateout-----total--mymatch
2009-01-05 5 3
2009-03-01 4 3
2009-04-01 4 3
================================
SELECT o.dateout, o.valueout AS total, count(i.datein) AS mymatch
FROM (SELECT dateout, count(*) valueout FROM outtable GROUP BY dateout) o
LEFT JOIN intable i ON i.datein BETWEEN o.dateout and ADDDATE(o.dateout, INTERVAL 1 MONTH)
GROUP BY o.dateout, o.valueout
================================
Outtable
dateout-----valueout
2009-01-05 05
2009-01-05 06
2009-01-05 07
2009-01-05 50
2009-01-05 51
2009-03-01 05
2009-03-01 06
2009-03-01 07
2009-03-01 18
2009-04-01 05
2009-04-01 06
2009-04-01 07
2009-04-01 21
Intable
datein------valuein
2009-01-05 12
2009-01-06 06
2009-01-08 07
2009-03-03 06
2009-03-04 07
2009-03-05 05
2009-04-02 05
2009-04-15 06
2009-04-16 07
But I also want to select values within the data ranges where valuein=valueout. Thanks in advance, Aaron
The end result should read.
dateout-----total--mymatch
2009-01-05 5 2
2009-03-01 4 3
2009-04-01 4 3
instead of this which the query below produces.
dateout-----total--mymatch
2009-01-05 5 3
2009-03-01 4 3
2009-04-01 4 3
================================
SELECT o.dateout, o.valueout AS total, count(i.datein) AS mymatch
FROM (SELECT dateout, count(*) valueout FROM outtable GROUP BY dateout) o
LEFT JOIN intable i ON i.datein BETWEEN o.dateout and ADDDATE(o.dateout, INTERVAL 1 MONTH)
GROUP BY o.dateout, o.valueout
================================
Outtable
dateout-----valueout
2009-01-05 05
2009-01-05 06
2009-01-05 07
2009-01-05 50
2009-01-05 51
2009-03-01 05
2009-03-01 06
2009-03-01 07
2009-03-01 18
2009-04-01 05
2009-04-01 06
2009-04-01 07
2009-04-01 21
Intable
datein------valuein
2009-01-05 12
2009-01-06 06
2009-01-08 07
2009-03-03 06
2009-03-04 07
2009-03-05 05
2009-04-02 05
2009-04-15 06
2009-04-16 07