dbTalk Databases Forums  

help on aggregate functions

comp.databases.postgresql comp.databases.postgresql


Discuss help on aggregate functions in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default help on aggregate functions - 11-18-2008 , 05:32 AM






Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?

Reply With Quote
  #2  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM






Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #3  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #4  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #5  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #6  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #7  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #8  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
  #9  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: help on aggregate functions - 11-18-2008 , 05:39 AM



Coniglio Sgabbiato ha scritto:
Quote:
Hello, I am importing an old database into a new one with a new data
structure, in order to map the old relations to new ones I need to
perform some weird queries during the data import, now I have a problem
that I cannot solve, I have the result of this query:

select key_field,
min(cast(date1)) as d1,
min(cast(date2)) as d2,
min(cast(date3)) as d3,
min(cast(date4)) as d4,
min(cast(date5)) as d5,
min(cast(date6)) as d6
from import_table
group by key_field;

now, I have to calculate the min of d1, d2, d3, d4, d5, d6 for *each*
query, but I cannot find out a method to force min() to work on single
rows, even with a subquery. Any tip?
I resolved with least:

select key_field,
least(
min(cast(date1)),
min(cast(date2)),
min(cast(date3)),
min(cast(date4)),
min(cast(date5)),
min(cast(date6))
) as ancient_date
from import_table
group by key_field;

but I am curious, there is any way to do it avoiding least() and using
min()?


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.