Re: Compare 2 resultsets of db-query
| From: | Analysis & Solutions | Date: | Wed, 12 Jun 2002 15:28:13 +0000 |
| Subject: | Re: Compare 2 resultsets of db-query | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-101751@lists.php.net to get a copy of this message | ||
On Wed, Jun 12, 2002 at 04:54:30PM +0200, Danny Kruitbosch wrote:
> Analysis & Solutions wrote:
> >Hey Danny:
> >
> >On Mon, Jun 10, 2002 at 10:09:12PM +0200, Danny Kruitbosch wrote:
> >
> >>Query1: SELECT FIELD1, COUNT(FIELD2) AS TOTAL from TABLE GROUP BY FIELD1
> >>Query2: SELECT FIELD1, COUNT(FIELD2) AS SUB from TABLE WHERE FIELD2=1
> >>GROUP BY FIELD1
>
> FIELD 1 contains IP address pool names (not unique), field2 the status
> (0 free, 1 leased). So what I try to do is get an overview of the total
> number of IP adresses in a pool and the number of leased addresses.
> There's a fourth field that contains the actual address.
0 and 1 in FIELD2? That makes this a piece of cake! All you need is one
query. In Query1, do a SUM(FIELD2) rather than COUNT(FIELD2). Forget
about Query2.
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409