Re: [SQL] date arithmetic over calender year boundaries

2004-04-28 Thread Bruno Wolff III
On Wed, Apr 28, 2004 at 16:12:34 +1200,
  Ray Jackson <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> The following Postgres 7.1 query extracts aggregated data for an
> arbitrary period within each year for sites in a table containing
> 30 years of temperature data.

It isn't completely clear what you want to do, but you might be able to
use date_part in a where clause to limit the data used for each year
if the range within each year is the same.

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


[SQL] select distinct and order by

2004-04-28 Thread Stijn Vanroye
Hello everybody,

I have a short question:

I'm trying to run the following query:
select distinct on (staff_id) staff_id, fullname, loginname from staff
where staff_id in 
  (select staff_id from staffmembership where staffgroup_id=#SomeIdValue#)
order by fullname

I get the follwing error:
select distinct on expressions must match the initial order by expression

Does this mean that I can only order by the same fields as the ones that I use in the 
distinct?
If so, is there still a way that I can select distinct on the keyfield, and still sort 
by the name. However unlikely, it could happen that two people have the same name, so 
a distinct on fullname could make problems.

The facts:
- PostgreSQL 7.3.2 running on RH 9
- pgODBC 7.3.0200
- Borland Delphi 7 enterprise

Regards,

Stijn Vanroye

-=[Today I got more responsabilities from my boss, as from now I'm responsible for 
everything that goes wrong ...]=-

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] select distinct and order by

2004-04-28 Thread Viorel Dragomir



I don't know if this will work, but why not try it 
? :)
 
select distinct fullname, distinct staff_id, loginname from staffwhere 
staff_id in   (select staff_id from staffmembership where 
staffgroup_id=#SomeIdValue#)order by fullname, staff_id
 
 
Next one is more complicate but with more chances 
to succeed :)
 
select staff_id, fullname, loginname from 
(
select distinct on (staff_id) staff_id, fullname, loginname from 
staffwhere staff_id in   (select staff_id from staffmembership 
where staffgroup_id=#SomeIdValue#)order by staff_id
)
order by fullname
 
Let me know
:)

  - Original Message - 
  From: 
  Stijn 
  Vanroye 
  To: [EMAIL PROTECTED] 
  Sent: Wednesday, April 28, 2004 
  12:27
  Subject: [SQL] select distinct and order 
  by
  Hello everybody,I have a short question:I'm 
  trying to run the following query:select distinct on (staff_id) staff_id, 
  fullname, loginname from staffwhere staff_id in   (select 
  staff_id from staffmembership where staffgroup_id=#SomeIdValue#)order by 
  fullnameI get the follwing error:select distinct on expressions 
  must match the initial order by _expression_Does this mean that I can 
  only order by the same fields as the ones that I use in the distinct?If 
  so, is there still a way that I can select distinct on the keyfield, and still 
  sort by the name. However unlikely, it could happen that two people have the 
  same name, so a distinct on fullname could make problems.The 
  facts:- PostgreSQL 7.3.2 running on RH 9- pgODBC 7.3.0200- Borland 
  Delphi 7 enterpriseRegards,Stijn Vanroye-=[Today I got 
  more responsabilities from my boss, as from now I'm responsible for everything 
  that goes wrong ...]=(end of 
  broadcast)---TIP 7: don't forget to increase your 
  free space map settings


Re: [SQL] select distinct and order by

2004-04-28 Thread Stijn Vanroye
I solved it. Your first answer gave me a slap on the head (and by god I needed one :-) 
). I simply used this:

select distinct staff_id, fullname, loginname from staff
where staff_id in 
  (select staff_id from staffmembership where staffgroup_id=#someid#)
order by fullname

By omitting the on(staff_id) I believe it now distincts on all the fields. At first I 
was thinking that this would cause a problem, but it is not. Even if the fullname and 
the loginname are different the id will still seperate them. And a situation where the 
id is the same and the fullname and loginname are different is impossible.

In your first option you use the word 'distinct' again, but this wil most certainly 
raise a parse error.

The second option will work. It's not that complicated but two subselects for 3 fields 
from one and the same table may be a bit much though :-)

Thanks for the help,

Stijn Vanroye

-Original Message-
From: Viorel Dragomir [mailto:[EMAIL PROTECTED]
Sent: woensdag 28 april 2004 11:54
To: Stijn Vanroye; [EMAIL PROTECTED]
Subject: Re: [SQL] select distinct and order by


I don't know if this will work, but why not try it ? :)

select distinct fullname, distinct staff_id, loginname from staff
where staff_id in 
  (select staff_id from staffmembership where staffgroup_id=#SomeIdValue#)
order by fullname, staff_id


Next one is more complicate but with more chances to succeed :)

select staff_id, fullname, loginname from (
select distinct on (staff_id) staff_id, fullname, loginname from staff
where staff_id in 
  (select staff_id from staffmembership where staffgroup_id=#SomeIdValue#)
order by staff_id
)
order by fullname

Let me know
:)
- Original Message - 
From: Stijn Vanroye 
To: [EMAIL PROTECTED] 
Sent: Wednesday, April 28, 2004 12:27
Subject: [SQL] select distinct and order by


Hello everybody,

I have a short question:

I'm trying to run the following query:
select distinct on (staff_id) staff_id, fullname, loginname from staff
where staff_id in 
  (select staff_id from staffmembership where staffgroup_id=#SomeIdValue#)
order by fullname

I get the follwing error:
select distinct on expressions must match the initial order by expression

Does this mean that I can only order by the same fields as the ones that I use in the 
distinct?
If so, is there still a way that I can select distinct on the keyfield, and still sort 
by the name. However unlikely, it could happen that two people have the same name, so 
a distinct on fullname could make problems.

The facts:
- PostgreSQL 7.3.2 running on RH 9
- pgODBC 7.3.0200
- Borland Delphi 7 enterprise

Regards,

Stijn Vanroye

-=[Today I got more responsabilities from my boss, as from now I'm responsible for 
everything that goes wrong ...]=-

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]