jeudi 28 janvier 2016

SQL query for Invoices

Hello,

I am having trouble writing and SQLite query that needs to list invoices related to a client but also within that listing of invoices, the total of the invoice that contains one or more amounts per line item.

I have three tables: "clients" table, "invoices" table (foreign key to clients table), and "line_items" table (foreign key to invoices table).

So the result would look like this:

(Client Information)

Invoice #1..........$5000 (total of line items for Invoice 1)
Invoice #2..........$3000 (total of line items for Invoice 2)
Invoice #3..........$8000 (total of line items for Invoice 3) etc…

I was able to achieve the results I wanted with PHP using nested loops, but would like to do this with SQL statement without the need for multiple calls to the database.

I am teaching myself here, so I hope I am making sense in my description.

Any help in the right direction would be appreciated.

Thanks

Aucun commentaire:

Enregistrer un commentaire