Re: [SQL] F_TABLE_NUMBER_RANGE equivalent in Postgresql

2011-08-15 Thread Pavel Stehule
Hello this is not built in MSSQL, but PostgreSQL has a "generate_series" function Regards Pavel Stehule 2011/8/16 msi77 : > > Are you sure that dbo.F_TABLE_NUMBER_RANGE is in SQL Server? > I suppose that this is UDF written by user. > > > 16.08.2011, 08:53, "Yuan HOng" : >> Hi, >> >> With MS-SQ

Re: [SQL] F_TABLE_NUMBER_RANGE equivalent in Postgresql

2011-08-15 Thread msi77
Are you sure that dbo.F_TABLE_NUMBER_RANGE is in SQL Server? I suppose that this is UDF written by user. 16.08.2011, 08:53, "Yuan HOng" : > Hi, > > With MS-SQL sever, there is a built-in utility function > dbo.F_TABLE_NUMBER_RANGE which generates a list of number between the > given range. For e

[SQL] F_TABLE_NUMBER_RANGE equivalent in Postgresql

2011-08-15 Thread Yuan HOng
Hi, With MS-SQL sever, there is a built-in utility function dbo.F_TABLE_NUMBER_RANGE which generates a list of number between the given range. For example: select dbo.F_TABLE_NUMBER_RANGE(1, 5) will return: number --- 1 2 3 4 5 This is extremely convenient for generating consecutive dat

Re: [SQL] pgadmin debugger

2011-08-15 Thread David Harel
On Mon, 2011-08-15 at 06:49 -0700, Adrian Klaver wrote: > On Sunday, August 14, 2011 11:33:13 am David Harel wrote: > > On Sun, 2011-08-14 at 11:07 -0700, Adrian Klaver wrote: > > > On Sunday, August 14, 2011 10:15:43 am David Harel wrote: > > > > On Sat, 2011-08-13 at 12:56 -0700, Adrian Klaver wr

Re: [SQL] bigint and unix time

2011-08-15 Thread Janiv Ratson
Hi and thanks, If my 'time' column is being saved as bigint: 128732389900. How do I write a query to check if the 'time' field is greater than now - 30 (past 30 days)? Thanks, Janiv,. -Original Message- From: Adrian Klaver [mailto:adrian.kla...@gmail.com] Sent: Sunday, August 14, 20

Re: [SQL] bigint and unix time

2011-08-15 Thread Adrian Klaver
On Sunday, August 14, 2011 11:23:08 pm Janiv Ratson wrote: > Hi and thanks, > If my 'time' column is being saved as bigint: 128732389900. > How do I write a query to check if the 'time' field is greater than now - > 30 (past 30 days)? So what you want is not what values are greater than some p

Re: [SQL] Calculate the ratio

2011-08-15 Thread Andreas Forø Tollefsen
Great. This works like I wanted. Thanks!

Re: [SQL] pgadmin debugger

2011-08-15 Thread Adrian Klaver
On Sunday, August 14, 2011 11:33:13 am David Harel wrote: > On Sun, 2011-08-14 at 11:07 -0700, Adrian Klaver wrote: > > On Sunday, August 14, 2011 10:15:43 am David Harel wrote: > > > On Sat, 2011-08-13 at 12:56 -0700, Adrian Klaver wrote: > > > > On Saturday, August 13, 2011 12:39:44 pm David Hare

Re: [SQL] Calculate the ratio

2011-08-15 Thread David Johnston
Replace the “1” in the case with “area”… like the msi77 said From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of David Johnston Sent: Monday, August 15, 2011 9:08 AM To: 'Andreas Forø Tollefsen'; pgsql-sql@postgresql.org Subject: Re: [SQL] Calculate the rat

Re: [SQL] Calculate the ratio

2011-08-15 Thread David Johnston
SELECT cols, SUM( CASE WHEN cf = 1 THEN 1 ELSE 0 END ) AS sum_1, SUM ( CASE WHEN cf = 0 THEN 1 ELSE 0 END ) AS sum_0 FROM table WHERE cf IN (0, 1) GROUP BY cols From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Andreas Forø Tollefsen Sent: Monday,

Re: [SQL] Calculate the ratio

2011-08-15 Thread msi77
Hi, Try this select gridyear, gwcode, sum(case when cf=1 then area else o end) as cf1, sum(case when cf=0 then area else 0 end) as cf0 from table group by gridyear, gwcode http://sql-ex.ru/help/select8.php#case 15.08.2011, 16:21, "Andreas Forø Tollefsen" : > Hi all, > > This is probably quite

[SQL] Calculate the ratio

2011-08-15 Thread Andreas Forø Tollefsen
Hi all, This is probably quite simple. I want to calculate the ratio of each country (gwcode) which experiences a 1 in one column (cf). Structure: gid; gridyear; gwcode; area; cf I want to select the SUM(area) WHERE cf = 1 into one column, and SUM(area) WHERE cf = 0 into another column and grou