[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SELECT help


Sir, haven't you posted this before? It looks familiar.

You can't apply an aggregate function to an entire table if the SELECT statement has a GROUP BY clause. The aggregate function will return totals for the groups, not for the entire table.

Bob Hall

Can someone help me combine this statement ...

SELECT d.*, b.invoice_id FROM domain_info d LEFT JOIN billing_info b ON d.domain_id=b.domain_id WHERE billing_cycle = '12' OR billing_cycle = 'Z' OR billing_cycle = 'C' GROUP BY domain_name

with this statement ...

SELECT sum(ammount_due) FROM billing_info WHERE domain_id = $domain_id AND status = 0

The code is for billing software to manage the accounts of my server clients. In the first statement I am selecting information about each domain from the table domain_info that are billable for this billing cycle. Also in the first statement I am checking to see if any invoice_ids exist for the domain in the table billing_info. If there are no ids, the code knows to add a setup fee to the charge. If there are ids, then they domain has already been charges in the past and been billed for the one-time setup fee.

The second statment gets the entire ammount owed from the table billing_info. Anytime a domain incurs a charge (positive) or pays an invoice (neagtive), a line is added with this in the ammount_due collumn.

I can't seem to get an error free result ... can anyone offer suggestions on some working codes that gets both of these statments into one?

Thanks!

Nick

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <mysql-thread65296@xxxxxxxxxxxxxxx>
To unsubscribe, e-mail <mysql-unsubscribe-rjhalljr=starpower.net@xxxxxxxxxxxxxxx>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Know thyself? Absurd direction!
Bubbles bear no introspection.     -Khushhal Khan Khatak

---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <mysql-thread65363@xxxxxxxxxxxxxxx>
To unsubscribe, e-mail <mysql-unsubscribe-treed=ultraviolet.org@xxxxxxxxxxxxxxx>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



This mailing list archive is a service of Copilot Consulting.