GROUP BY clause diff in Sybase and Oracle
500237Mar 16 2009 — edited Mar 17 2009Hi,
I am migrating code from Sybase to Oracle and came across a strange issue which is widely known to others :)
In Sybase , one can use columns or calculations in the SELECT expressions that don't appear
in the GROUP BY clause of the query. Like
SELECT order.custid,customer.name,MAX(payments)
-> FROM order, customer
-> WHERE order.custid = customer.custid
-> GROUP BY order.custid;
works fine but for SQL we need to add customer.name to GROUP BY clause.
On the similar lines, here is my SQL query
INSERT INTO GTT_CTRT_recalc_proc
(id_fin_rec,
id_imnt,
id_instr_opn,
dt_instr_opn,
dt_opn,
dt_cls_loanet,
dt_prcss,
am_invst)
SELECT t1.id_fin_rec,
t1.id_imnt,
t1.id_instr_opn,
t1.dt_instr_opn,
t1.dt_opn,
NVL(t1.dt_cls_loanet, l_dt_to),
t1.dt_prcss,
SUM(t2.am_invst) + (0.123 * (1 - abs(sign(0 - SUM(t2.am_invst)))))
FROM GTT_CTRT_TEMP_recalc_process t1, GTT_CTRT_TEMP_recalc_process t2
WHERE t2.id <= t1.id
AND t2.id_imnt = t1.id_imnt
AND t2.id_instr_opn = t1.id_instr_opn
AND t2.dt_instr_opn = t1.dt_instr_opn
GROUP BY t1.id_imnt,
t1.id_instr_opn,
t1.dt_instr_opn,
t1.dt_opn,
t1.dt_cls_loanet,
t1.dt_prcss;
Which does not have t1.id_fin_rec in GROUP BY failing it in SQL.
I know that if I add this column in GROUP BY it will work fine but I am told to keep the functionality as it is as the result before and after adding the column would be diff of-course.
Please guide me about what can be done in this situation and is there any work around for this?
Thanks,
Aashish