I have an SQL statement as follows:
SELECT x.xreport_id, MIN(xd.xd_worked) as date_from, MAX(xd.xd_worked) as date_to FROM xreports x, xreport_detail xd WHERE xd.xreport_id = x.xreport_id AND TO_DAYS('2005-02-02') - TO_DAYS(date_from) >= 0 AND TO_DAYS('2005-02-14') - TO_DAYS(date_to) <= 0 GROUP BY x.xreport_id ORDER BY date_from DESC
If i do this version, it says Unknown column 'date_from' in 'where clause'. I understand that date_from and date_to are not columns, but I thought it would recognize them because i created them with the AS feature due to the fact that the original value is a calculation..
Then, I tried this:
SELECT x.xreport_id, MIN(xd.xd_worked) as date_from, MAX(xd.xd_worked) as date_to FROM xreports x, xreport_detail xd WHERE xd.xreport_id = x.xreport_id AND TO_DAYS('2005-02-02') - TO_DAYS(MIN(xd.xd_worked)) >= 0 AND TO_DAYS('2005-02-14') - TO_DAYS(MAX(xd.xd_worked)) <= 0 GROUP BY x.xreport_id ORDER BY date_from DESC
Now if I replace "date_from" and "date_to" with the actual computation (ie: MAX() and MIN() ), I get this: Invalid use of group function.
How can I get the TO_DAYS to use the MAX or MIN value that I am creating?
Thanks in advance...