SQL Query with SUM() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: SQL Query with SUM() (/showthread.php?tid=81429) |
SQL Query with SUM() - BFlokstra - 03-01-2022 Hi guys, Here is some background: I am building a claim system for our volunteers. Any time a volunteer uses their own car to get to a shift, they get €0,19 per kilometer to go towards gas. If they use public transport they get 100% of the fare reimbursed. What I'm trying to do now is get all claims for a specific volunteer, with a total of the payable price. Now, the volunteers can claim multiple shifts in one claim. To this end, I have set up two tables: claims: id int [PRIMARY, auto_inc] volunteer int, date date approved date payed date denied date iban varchar[18] account_holder TEXT claimrows: id int [PRIMARY, auto_inc] claim int shift int address TEXT kilometers int amount double(5,2) vehicle_type int payable double(5,2) (To make understanding the below easier, I translated the table, column and row names to english. I haven't changed anything else, so it's exactly how it's set up) I've written this query: Code: SELECT I'm now having two problems:
|