samedi 14 février 2015

Update table based on another table in SQLite DataBase

I am using SQLite. There are two tables shown below.



Transaction_Tbl
ID Name Credit/Debit Value
1 ABC credit 10
1 ABC credit 10
2 DEF credit 20
2 DEF debit 40


(record for third employee EFG not present in the table)


Based on the table, Average_Tbl must be updated as below...



Average_Table
ID Name Avg(Credit-Debit)
1 ABC 20
2 DEF -20
3 EFG 0 (as no records for EFG in Transaction_Tbl)


Now if there is a record for EFG in Transaction_Tbl for Debit, then in Average_Tbl, the record for EFG must be negative (credit - debit => where credit must be taken as zero as no records for credit.).


How to do it?


Aucun commentaire:

Enregistrer un commentaire