I am implementing weekly reports I have the following query
SELECT fecha_muestra,
label,
seiz_traf,
call_comp_traf,
answ_traf,
TO_CHAR(fecha_muestra,'IW') AS SEMANA
FROM V_GF_DATA_MSC_TRAF
WHERE TO_CHAR(fecha_muestra,'IW')='40'
AND TO_CHAR (fecha_muestra, 'mi') = '00'
ORDER BY fecha_muestra ASC, label ASC
Which brings me the 40th week, but I have a problem that when executing the query it brings me the 40th week of every year and I would like it to show me the one of each year
This is an example of the output I get:
You can try this code to return everything from 2018 week 40.
The problem is that in the WHERE condition you must specify the YEAR so that it does not return the previous years. In this example, the YEAR column is added and the WHERE clause is also modified so that it returns only 2018.
If you want, you can modify the
AND to_number(to_char(fecha_muestra, 'HH24')) = '2018'
so that it returns the current year and you should not modify the query year by year.AND to_number(to_char(fecha_muestra, 'YYYY')) = to_number(to_char(sysdate, 'YYYY'))