what's the difference in terms of result [message #346803] |
Tue, 09 September 2008 13:42 |
beetel
Messages: 96 Registered: April 2007
|
Member |
|
|
SELECT a.pindex,
TO_CHAR(LAST_DAY(TRUNC(a.l_dt)), 'YYYY-MM-DD HH24:MI:SS') AS l_dt,
SUM(a.cond) AS cond,
'N' flag
FROM MY_TABLE a
WHERE l_dt between :first_day_current_month and :last_day_current_month
AND a.pindex IN
(SELECT DISTINCT b.pindex
FROM MY_TABLE b
WHERE b.l_dt BETWEEN :prev_date AND :current_date)
GROUP BY pindex, LAST_DAY(TRUNC(l_dt)), 'N'
versus
SELECT a.pindex,
TO_CHAR(LAST_DAY(TRUNC(a.l_dt)), 'YYYY-MM-DD HH24:MI:SS') AS l_dt,
SUM(a.cond) AS cond,
'N' flag
FROM MY_TABLE a
WHERE l_dt between :first_day_current_month and :last_day_current_month
AND l_dt between :prev_date AND :current_date
GROUP BY pindex, LAST_DAY(TRUNC(l_dt)), 'N'
|
|
|
|
|
|
|
Re: what's the difference in terms of result [message #346889 is a reply to message #346803] |
Wed, 10 September 2008 00:57 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
> what's the difference in terms of result
Strange to put the question into title, but, the answer depends on MY_TABLE data and input conditions. But, you may try both queries with two rows having the same PINDEX, non-zero COND column and L_DT equal to TO_DATE( '05.09.2008', 'dd.mm.yyyy' ) (first row)
TO_DATE( '07.09.2008', 'dd.mm.yyyy' ) (second row)
and input conditions FIRST_DATE_CURRENT_MONTH = TO_DATE( '01.09.2008', 'dd.mm.yyyy' )
LAST_DATE_CURRENT_MONTH = TO_DATE( '30.09.2008', 'dd.mm.yyyy' )
PREV_DATE = TO_DATE( '06.09.2008', 'dd.mm.yyyy' )
CURRENT_DATE = TO_DATE( '10.09.2008', 'dd.mm.yyyy' )
|
|
|