This is the first table:
Table source
(
id int,
accno varchar(50),
duedate date,
plafond int,
customer_name varchar(100),
bicoll int,
ccy varchar(5),
parent_id int
)
This is the second table:
Table result
(
id int,
accno varchar(50),
duedate date,
plafond int,
customer_name varchar(100),
bicoll int,
ccy varchar(5),
jumlah int
)
From those tables, I need to make INSERT
statement to the first table (source) with theseconditions :
if plafond < 1000 then group by ccy with accno = "GRUP1", duedate = null, plafond = SUM(plafond), customer_name = "GRUP1", bicoll = NULL, jumlah = COUNT THE ROWS THAT HAVE BEEN GROUPED
if plafond >= 1000 and < 5000 group by customer_name and ccy with due_date = max(duedate), plafond = sum(plafond), bicoll = max(bicoll), jumlah = COUNT THE ROWS THAT HAVE BEEN GROUPED
if plafond >= 5000 do not group so that fields jumlah = 1
How to write this INSERT
statement?
And the second table has relation between parent_id
(source
) and id
(result
), so if I want to modify something, I used those relation using UPDATE
statement.
I am working on an UPDATE
statement, but what confuses me is the INSERT
statement with those conditions
Please help me, it has been bothering me for weeks. Thank you