[SQL] combine SQL SELECT statements into one

2010-02-01 Thread Neil Stlyz
Good Evening, Good Morning Wherever you are whenever you may be reading this. I am new to this email group and have some good experience with SQL and PostgreSQL database. I am currently working on a PHP / PostgreSQL project and I came upon something I could not figure out in SQL. I was wonderi

Re: [SQL] [NOVICE] combine SQL SELECT statements into one

2010-02-01 Thread A. Kretschmer
In response to Neil Stlyz : > Good Evening, Good Morning Wherever you are whenever you may be reading this. > > I am new to this email group and have some good experience with SQL and > PostgreSQL database. > > > I am currently working on a PHP / PostgreSQL project and I came upon something > I

Re: [SQL] combine SQL SELECT statements into one

2010-02-01 Thread msi77
Hi, SELECT (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-02-01') as count1, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-20') as count2, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-01') as count3 Serge > Good Evenin

Re: [SQL] combine SQL SELECT statements into one

2010-02-01 Thread msi77
Hi, SELECT (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-02-01') as count1, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-20') as count2, (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-01') as count3 Serge > Good Evenin

Re: [SQL] combine SQL SELECT statements into one

2010-02-01 Thread Leo Mannhart
msi77 wrote: > Hi, > > SELECT > (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-02-01') > as count1, > (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-20') > as count2, > (SELECT COUNT(distinct model) FROM inventory WHERE modified >= '2010-01-01') >

[SQL] selecting rows tagged with "a" but not "b"

2010-02-01 Thread 8q5tmkyqry
Hi, I have a two tables: article articleID, name, content tags articleID, tag I want to find all articles that are tagged with "a" but not "b" how do I do this? what I'd like to do is: select articleID from tags where tag="a" SUBTRACT select articleID from tags where tab="b" how do I do t

Re: [SQL] selecting rows tagged with "a" but not "b"

2010-02-01 Thread Milen A. Radev
8q5tmky...@sneakemail.com написа: Hi, I have a two tables: article articleID, name, content tags articleID, tag I want to find all articles that are tagged with "a" but not "b" how do I do this? what I'd like to do is: select articleID from tags where tag="a" SUBTRACT select articleID fro

Re: [SQL] selecting rows tagged with "a" but not "b"

2010-02-01 Thread Oliveiros C,
Darrell, Can you provide a little more information and background on your problem. please? What values can the "tag" column assume? Just "a" and "b" ? Both? Please give examples of table contents and desired output, your mail doesn't contain enough info to give you more advises Thank you

Re: [SQL] selecting rows tagged with "a" but not "b"

2010-02-01 Thread Andreas Gaab
Hi Darrell, SELECT DISTINCT articleID FROM tags WHERE tag = "a" EXCEPT SELECT DISTINCT articleID FROM tags WHERE tag = "b"; Regards, Andreas -Ursprüngliche Nachricht- Von: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] Im Auftrag von 8q5tmky...@sneakemail.com G

Re: [SQL] selecting rows tagged with "a" but not "b"

2010-02-01 Thread Andreas Kretschmer
8q5tmky...@sneakemail.com <8q5tmky...@sneakemail.com> wrote: > Hi, > > I have a two tables: > > article > articleID, name, content > > tags > articleID, tag > > I want to find all articles that are tagged with "a" but not "b" > > how do I do this? select a.* from article left join tags t on

Re: [SQL] selecting rows tagged with "a" but not "b"

2010-02-01 Thread Yeb Havinga
Andreas Kretschmer wrote: 8q5tmky...@sneakemail.com <8q5tmky...@sneakemail.com> wrote: Hi, I have a two tables: article articleID, name, content tags articleID, tag I want to find all articles that are tagged with "a" but not "b" how do I do this? select a.* from article left joi

[SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
I'm really trying to understand how the tablefunc crosstab function works, to no avail. I have a table that looks like this: customer_id integer date timestamp with time zone amount numeric(10,4) There are rows in this table every-time a customer gets charged an amount, which is multiple times

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
I'm flying blind here since I have nothing that looks like the structure you described to experiment on, but based on some crosstabs I have set up this should get you started. Explanatory notes follow. SELECT pivot.* FROM crosstab(' --row header, column header, cell value SELECT customer_i

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
On 2010-02-01, at 11:34 , Lee Hachadoorian wrote: > You basically have three parts: > > 1) SELECT query in the form (row header, column header, cell value). In this > case it is an aggregate query so that you can sum the transactions over a > given day. > > 2) List of column headers. If you wa

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
The output column data type (day1, day2, etc.) is supposed to match the value data type. I used numeric(10,4) because that's what your original post specified, but the billed_duration column in your most recent post looks like it might be integer? (Or is it defined as numeric(10,4), but you never e

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
On 2010-02-01, at 14:22 , Lee Hachadoorian wrote: > The output column data type (day1, day2, etc.) is supposed to match the value > data type. I used numeric(10,4) because that's what your original post > specified, but the billed_duration column in your most recent post looks like > it might be

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
On Mon, Feb 1, 2010 at 3:11 PM, Adam Sherman wrote: > Actually, the query I was running is: > > SELECT >cust_id as customer, >date_trunc(''day'', date) AS day, > SUM(billed_duration)/60.0::numeric(10,4) AS minutes > > billed_duration is an integer. Make sense? > > If billed_duration i