Re: REPOST: Trouble with SQL conversion

From: "Richard Ellerbrock" <richarde(at)eskom(dot)co(dot)za>
To: <chriskl(at)familyhealth(dot)com(dot)au>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: REPOST: Trouble with SQL conversion
Date: 2002-04-11 14:08:38
Message-ID: scb5b513.058@eskom.co.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Ok, did that - now it works but returns no records.

What I am after is to reduce the right hand table to one row matching
the left table. There may be no, one or many matching records in the
right table, but I want to group them on the key and find out the number
of records in the right table at the same time.

This works just fine in that other database :-)

>>> Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> 2002/04/11
03:28:32 >>>
> SELECT base.baseindex, base.subnetsize, base.descrip, base.baseaddr,
> base.admingrp, count(ipaddr.baseindex) AS cnt FROM base
> LEFT JOIN ipaddr ON base.baseindex=ipaddr.baseindex WHERE
> base.baseaddr
> BETWEEN 2473473024 AND 2473473151 AND base.customer=1
> GROUP BY base.baseindex
> ORDER BY base.baseaddr;

> 0: ERROR: Attribute base.subnetsize must be GROUPed or used in an
> aggregate function

Do what it says. Add base.subnetsize to the GROUP BY. You'll
probably
need to add base.descrip, base.baseaddr and base.admingrp as well.

Chris

Browse pgsql-sql by date

  From Date Subject
Next Message Jean-Michel POURE 2002-04-11 14:25:34 Re: Transactional vs. Read-only (Retrieval) database
Previous Message Rajesh Kumar Mallah 2002-04-11 14:04:28 using output of a subselect in LIKE/ILIKE