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
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
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
"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
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)
>
> 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
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
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
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
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
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
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
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
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.
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
( 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
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
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:
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<
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
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
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
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
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:
"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?
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
26 matches
Mail list logo