Re: [SQL] subquery question

2009-03-12 Thread Bob Henkel
Does this help Here is my test table data. ID;DATE;VALUE 1;"2009-03-13";5 2;"2009-03-13";2 3;"2009-03-11";1 4;"2009-03-11";2 5;"2009-03-11";3 SELECT mydate AS day, SUM(CASE WHEN id % 2 = 1 THEN value END) AS sum_odd, SUM(CASE WHEN id % 2 = 0 THEN value END) AS sum_even FROM xyz GROUP

[SQL] subquery question

2009-03-12 Thread Sebastian Böhm
Hi, I have a table: (date timestamp, id integer, value integer) What Iam trying to do is to get a result that looks like this: day sum_oddsum_even 2009-01-01 656578867 2009-01-02 876785 87667 basically a need to combine these two queries into one: SELECT

Re: [SQL] "Subquery must return only one column" & query optimization

2008-12-15 Thread Philippe Lang
pgsql-sql-ow...@postgresql.org wrote: > "Philippe Lang" writes: >> I was trying to run this query this morning: > >> -- >> SELECT > >> r.*, > >> ( >> SELECT > >> rl.reminder_header, >> rl.reminder_footer > >> FROM reminder_levels AS rl >> WHERE

Re: [SQL] "Subquery must return only one column" & query optimization

2008-12-15 Thread Tom Lane
"Philippe Lang" writes: > I was trying to run this query this morning: > -- > SELECT > r.*, > ( > SELECT > rl.reminder_header, > rl.reminder_footer > FROM reminder_levels AS rl > WHERE rl.lookup = > ( > SELECT MAX(rem

[SQL] "Subquery must return only one column" & query optimization

2008-12-15 Thread Philippe Lang
Hi, I was trying to run this query this morning: -- SELECT r.*, ( SELECT rl.reminder_header, rl.reminder_footer FROM reminder_levels AS rl WHERE rl.lookup = ( SELECT MAX(reminder_level_lookup)

Re: [SQL] Subquery problems

2007-06-22 Thread Masaru Sugawara
> > Original Message > Subject: Re:[SQL] Subquery problems > From: Masaru Sugawara <[EMAIL PROTECTED]> > To: Ranieri Mazili <[EMAIL PROTECTED]> > Date: 21/6/2007 13:25 > > On Tue, 19 Jun 2007 09:17:22 -0300 > > Ranieri Mazili <[EMAIL PROTECTED]&g

Re: [SQL] Subquery problems

2007-06-21 Thread Masaru Sugawara
On Tue, 19 Jun 2007 09:17:22 -0300 Ranieri Mazili <[EMAIL PROTECTED]> wrote: Hi, This reply is not accurate, but I think there are helpful hints. -- Masaru Sugawara select C.id_production_area, B.id_machine_type, A.h_month as month, max(A.n) as div_mes, cast((sum(A.qty_employees_t

[SQL] Subquery problems

2007-06-19 Thread Ranieri Mazili
Hello, I'm having another "problem", I have a function that declares 12 variable, one per month and each them execute a select like bellow: *DIV_MES01 := (select count(distinct production_date) from production where extract(month from production_date) = '01' and extract(year from production_da

Re: [SQL] subquery abnormal behavior

2006-12-11 Thread Aaron Bono
On 12/11/06, Shoaib Mir <[EMAIL PROTECTED]> wrote: Oh that explains a lot... Thank you, - Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 12/11/06, Michael Glaesemann <[EMAIL PROTECTED]> wrote: > > > On Dec 11, 2006, at 15:48 , Shoaib Mir wrote: > > > create table myt1 (a numeri

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Shoaib Mir
Oh that explains a lot... Thank you, - Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 12/11/06, Michael Glaesemann <[EMAIL PROTECTED]> wrote: On Dec 11, 2006, at 15:48 , Shoaib Mir wrote: > create table myt1 (a numeric); > create table myt2 (b numeric); > > select a from myt1

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Michael Glaesemann
On Dec 11, 2006, at 15:48 , Shoaib Mir wrote: create table myt1 (a numeric); create table myt2 (b numeric); select a from myt1 where a in (select a from myt2); This should be giving an error that column 'a' does not exist in myt2 but it runs with any error... The a in the IN clause is the

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Shoaib Mir
I just noticed the same behavior in Oracle and SQL Server as well :) Regards, - Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 12/11/06, Shoaib Mir <[EMAIL PROTECTED]> wrote: I just noticed an abnormal behavior for the subquery: create table myt1 (a numeric); create table myt2 (b n

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Rajesh Kumar Mallah
On 12/11/06, Shoaib Mir <[EMAIL PROTECTED]> wrote: I just noticed an abnormal behavior for the subquery: create table myt1 (a numeric); create table myt2 (b numeric); select a from myt1 where a in (select a from myt2); This should be giving an error that column 'a' does not exist in myt2 b

[SQL] subquery abnormal behavior

2006-12-10 Thread Shoaib Mir
I just noticed an abnormal behavior for the subquery: create table myt1 (a numeric); create table myt2 (b numeric); select a from myt1 where a in (select a from myt2); This should be giving an error that column 'a' does not exist in myt2 but it runs with any error... I had been trying it on 8.

Re: [SQL] Subquery alternatives?

2006-09-05 Thread codeWarrior
I dont think you need the double-left join SELECT * FROM STORIES ST LEFT JOIN TAGS TG ON TG.tagkey = ST.storykey WHERE TG.tag = "science" "MRKisThatKid" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, i've posted this in various places but I'm really struggling to > find

Re: [SQL] SQL subquery (count distinct) - Any Ideas?

2005-04-22 Thread Ramakrishnan Muralidharan
( CS.SESSION_DATE AS DATE ) = CAST( '2005-04-13' AS DATE ) GROUP BY U.USER_ID Regards, R.Muralidharan -Original Message- From: Matt Fulford [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 13, 2005 10:59 PM To: pgsql-sql@postgresql.org Subject: [SQL] SQL subquery (count distinct) - Any Id

Re: [SQL] SQL subquery (count distinct) - Any Ideas?

2005-04-18 Thread Rod Taylor
On Wed, 2005-04-13 at 18:28 +0100, Matt Fulford wrote: > I'm trying to write a query to return the number of different customers > called on a single day. The database has a table called 'user', a table > called 'caller_session' which references a 'user' record, and a table called > 'call' whic

[SQL] SQL subquery (count distinct) - Any Ideas?

2005-04-18 Thread Matt Fulford
I'm trying to write a query to return the number of different customers called on a single day. The database has a table called 'user', a table called 'caller_session' which references a 'user' record, and a table called 'call' which references a 'caller_session'. This is my current attempt:

Re: [SQL] SubQuery

2001-10-03 Thread Stephan Szabo
On Thu, 4 Oct 2001 [EMAIL PROTECTED] wrote: > What mistake have I made? > > database1=# UPDATE mytable SET > NextNumber=NextNumber+1 > database1-# WHERE id='ID1' AND EffectiveDate= > database1-# (SELECT MAX(s2.EffectiveDate) FROM > mytable s2 > database1(# WHERE s2.id=id AND > s2.EffectiveDate<

[SQL] SubQuery

2001-10-03 Thread cnliou
Hi! I am using MyTable to serve the "next number" functionality like PGSQL embeded "sequence" offers. The only difference of the two is MyTable has 2 more fields - "ID" and "Starting Effective Date". The UPDATE SQL fails when I am trying to update record ID1 | 2001-08-01| 11 to

[SQL] Subquery with IN or EXISTS

2001-09-27 Thread A. Mannisto
Hello, does anybody know why this: SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2) equals this: SELECT * FROM tab WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2) but this: SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2 WHERE col3='huu') equals _NOT_ this: SELECT * FROM t

Re: [SQL] Subquery with IN or EXISTS

2001-09-27 Thread A. Mannisto
Carl van Tast <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Hi A., > > On 26 Sep 2001 07:24:41 -0700, [EMAIL PROTECTED] (A. Mannisto) > wrote: > > >Hello, > > > >does anybody know why this: > >SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2) > > > >equals this: > >SE

Re: [SQL] Subquery with IN or EXISTS

2001-09-26 Thread Carl van Tast
Hi A., On 26 Sep 2001 07:24:41 -0700, [EMAIL PROTECTED] (A. Mannisto) wrote: >Hello, > >does anybody know why this: >SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2) > >equals this: >SELECT * FROM tab WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = >col2) > >but this: >SELECT * FROM tab

Re: [SQL] Subquery error. Help please!!

2001-06-28 Thread Ross J. Reedstrom
I did something similar, but pu the subselect into a view, in the WHERE clause. SELECT * FROM modules m WHERE (m.module_ident = (SELECT max(modules.module_ident) AS max FROM modules WHERE (m.moduleid = modules.moduleid) GROUP BY modules.moduleid)); The equivalent for you would be something like:

Re: [SQL] Subquery error. Help please!!

2001-06-28 Thread Tom Lane
"kakerjak" <[EMAIL PROTECTED]> writes: > If the subquery is placed before the JOIN, like it is above, then the error > i get says 'parse error at or near "select"' > If i flip the subquery around with the laboratory table then i get 'parse > error at or near "("' Are you using 7.1?

Re: [SQL] Subquery error. Help please!!

2001-06-28 Thread Wei Weng
What version of postgresql are you using? On 27 Jun 2001 17:09:14 -0400, kakerjak wrote: > Hey all.. > > Here's the table definition. > CREATE TABLE "laboratory" ( > "id" "int4" NOT NULL, > "subid" "int2" NOT NULL, > "name" varchar(30) NOT NULL, > CONSTRAINT "laboratory_pkey" PRI