My first use of "case when" sql command. I needed to write an alert and the alert needed to be tested. Also test mail server was not working. So i replaced original e-mail addresses with our email addresses via "case when".
Example:
select email_address
case
when email_address = 'aaa' then 'bbb'
else 'ccc'
end
ABS returns absolute value of a number like
select ABS(-1) from dual : "1"
To extract day, month or year from sysdate we can use following:
select extract(day from sysdate) from dual
To select day, month or year from sysdate plus or minus some months we can use following:
select extract(year from add_months (sysdate,24)) from dual
To restrict the SQL with an aggregated condition "where" clause can not be used, "having" can be!
select po_header_id
from po.po_lines_all
where creation_date > sysdate -30
and sum(unit_price) > 1000
group by po_header_id
Generates "ORA-00934: group function is not allowed here" error.
Though following query works:
select po_header_id
from po.po_lines_all
where creation_date > sysdate -30
having sum(unit_price) > 1000
group by po_header_id
No comments:
Post a Comment