Re: Different type of query

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: PostgreSQL Admin <postgres(at)productivitymedia(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Different type of query
Date: 2008-06-11 19:01:29
Message-ID: 48502109.4090300@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> I would like to have multiple values nutrient_no:
> ndb_no | nutrient_no | nutrient_value
> --------+-------------+----------------
> 13473 | 203 | 24.18
> 13473 | 204 | 15.93
> 13473 | 205 | 0
> 13473 | 207 | 1.1
> 13473 | 208 | 247
> 13473 | 221 | 0
>
> I'm thinking:
> select nutrient_no, nutrient_value from nutrient_data where ndb_no =
> 13473 and (nutrient_no = '203' or nutrient_no = '204' or nutrient_no =
> 208);
>
Depending on what you are trying to achieve:

Particular ndb_no and multiple nutrient_no, note that output of ndb_no
is superfluous as it is always the same:
select nutrient_no, nutrient_value from nutrient_data where ndb_no =
13473 and nutrient_no in ('203', '204','208');

Size limited list (say top 5 nutrient values) for a given ndb_no:
select nutrient_no,nutrient_value from nutrient_data where ndb_no =
13473 order by nutrient_value limit 5;

Cheers,
Steve

In response to

Responses

  • Tsearch at 2008-06-12 12:47:44 from PostgreSQL Admin

Browse pgsql-sql by date

  From Date Subject
Next Message PostgreSQL Admin 2008-06-12 12:47:44 Tsearch
Previous Message PostgreSQL Admin 2008-06-11 19:00:28 Re: Different type of query