I am trying to get some data out of my database and stuck at one of the SELECT operations. Basically I have 2 tables, users and invoices: - users contains 4 fields: id:, name, tel_no, notes - invoices contains 9 fields: id, account_id, invoice_date, caller, date, hour, destination, total_duration,type_of_service
The total_duration field contains the information about the duration of a user call and it's expressed in seconds. The type_of_service field contains info about the destination of the call ("Land line, Another Net, Call Special Number").
I would like to be able to know the sum of minutes the user managed to accumulate when he made calls to "Land line, Another Net, Call Special Number".
What I have so far is:
$query=mysql_query("SELECT id,name,tel_no FROM users UNION SELECT id,account_id,caller FROM invoices WHERE caller LIKE \"%tel_no\"");
which gives me info about the tel numbers from the users table which are found in the invoices table ... but don't know how to get the total minutes used ...