Re: [GENERAL] SQL help - multiple aggregates

2016-08-18 Thread Francisco Olarte
CCing to the list ( if you are new to this list, messages come from the sender address, you have to use "reply all" ( at least in my MUA, web gmail ) to make your replies appear in the list ). On Thu, Aug 18, 2016 at 3:03 PM, wrote: > Hi Francisco, > thanks a lot. I will give it a try later Do

Re: [GENERAL] SQL help - multiple aggregates

2016-08-18 Thread David G. Johnston
On Thu, Aug 18, 2016 at 4:56 AM, wrote:​ > select custid, count(vendid) as c415 from cv where vendid = 415 group by > custid > ​[...] > > Is there a better way (by creating an aggregate function, perhaps) > ​You may find crosstab in the tablefuncs extension to be of use. ​ https://www.postgres

Re: [GENERAL] SQL help - multiple aggregates

2016-08-18 Thread Ladislav Lenart
Hello. On 18.8.2016 10:56, haman...@t-online.de wrote: > > Hi, > > I have a table cv with custid and vendid columns. Every entry represents the > purchase of a product > available from a specific vendor. > Now, for a set of "interesting" vendors, I would like to select a new table > custid, c

Re: [GENERAL] SQL help - multiple aggregates

2016-08-18 Thread Francisco Olarte
On Thu, Aug 18, 2016 at 10:56 AM, wrote: > I have a table cv with custid and vendid columns. Every entry represents the > purchase of a product > available from a specific vendor. > Now, for a set of "interesting" vendors, I would like to select a new table > custid, c415, c983, c1256 > based up

[GENERAL] SQL help - multiple aggregates

2016-08-18 Thread hamann . w
Hi, I have a table cv with custid and vendid columns. Every entry represents the purchase of a product available from a specific vendor. Now, for a set of "interesting" vendors, I would like to select a new table custid, c415, c983, c1256 based upon part queries select custid, count(vendid) as

Re: [GENERAL] SQL Help - Finding Next Lowest Value of Current Row Value

2011-10-11 Thread Jeff Adams
...@gmail.com] On Behalf Of Chris Curvey Sent: Saturday, October 01, 2011 10:55 PM To: Jeff Adams Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] SQL Help - Finding Next Lowest Value of Current Row Value On Sat, Oct 1, 2011 at 5:30 PM, Jeff Adams wrote: Greetings, I have a large table (~19

Re: [GENERAL] SQL Help - Finding Next Lowest Value of Current Row Value

2011-10-02 Thread Thomas Kellerer
Jeff Adams wrote on 01.10.2011 23:30: Greetings, I have a large table (~19 million records). Records contains a field identifying a vessel and a field containing an time (epoch). Using the current rows vessel and time values, I need to be able to find the next lowest time value for the vessel an

Re: [GENERAL] SQL Help - Finding Next Lowest Value of Current Row Value

2011-10-01 Thread Chris Curvey
On Sat, Oct 1, 2011 at 5:30 PM, Jeff Adams wrote: > Greetings, > > I have a large table (~19 million records). Records contains a field > identifying a vessel and a field containing an time (epoch). Using the > current rows vessel and time values, I need to be able to find the next > lowest time

Re: [GENERAL] SQL Help - Finding Next Lowest Value of Current Row Value

2011-10-01 Thread Chris Travers
On Sat, Oct 1, 2011 at 2:30 PM, Jeff Adams wrote: > Greetings, > > I have a large table (~19 million records). Records contains a field > identifying a vessel and a field containing an time (epoch). Using the > current rows vessel and time values, I need to be able to find the next > lowest time v

[GENERAL] SQL Help - Finding Next Lowest Value of Current Row Value

2011-10-01 Thread Jeff Adams
Greetings, I have a large table (~19 million records). Records contains a field identifying a vessel and a field containing an time (epoch). Using the current rows vessel and time values, I need to be able to find the next lowest time value for the vessel and use it to compute how much time has el

Re: [GENERAL] sql help, reusing a column

2010-04-29 Thread Andy Colson
On 04/29/2010 05:08 PM, Thomas Kellerer wrote: SELECT organization, state, lastdate, age(lastdate) FROM ( SELECT organization, state, (select max(idate) from times where customers.custid=times.custid and taskid = 27) as lastdate FROM customers ) t order by lastdate desc

Re: [GENERAL] sql help, reusing a column

2010-04-29 Thread Thomas Kellerer
Andy Colson wrote on 29.04.2010 23:51: Here is my query, which works: select organization, state, (select max(idate) from times where customers.custid=times.custid and taskid = 27) as lastdate, age( (select max(idate) from times where customers.custid=times.custid and taskid = 27) ) from custom

Re: [GENERAL] sql help, reusing a column

2010-04-29 Thread Andy Colson
On 4/29/2010 4:51 PM, Andy Colson wrote: I tried this: select organization, state, max(idate), age(max(idate)) from customers inner join times using(custid) where taskid = 27 group by organization, state order by idate desc nulls last; but get error that times.idate must appear in group by or

[GENERAL] sql help, reusing a column

2010-04-29 Thread Andy Colson
Here is my query, which works: select organization, state, (select max(idate) from times where customers.custid=times.custid and taskid = 27) as lastdate, age( (select max(idate) from times where customers.custid=times.custid and taskid = 27) ) from customers order by lastdate desc null

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread John McCawley
> I'm not clear how to move that "person_role.person = person.id" into the FROM statement. Does it matter? This should work: FROM person INNER JOIN person_role ON person.id = person_role.person LEFT OUTER JOIN instructors ON (person.id = instructors.person) LEFT OUTER JOIN class ON (instructor

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
On Mon, Nov 21, 2005 at 02:06:35PM -0800, Bill Moseley wrote: > The now working query (thanks to you!) is: No that doesn't work. It's dropping the people that have never been assigned a class to teach (i.e. don't have a row in the "instructors" link table). > FROM class INNER JOIN ins

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
On Mon, Nov 21, 2005 at 03:25:56PM -0600, John McCawley wrote: > I just noticed, also goofy is your ", person_role" in your from with no > criteria. I would generally put the "person_role.person = person.id" as > an INNER JOIN, and then only have the "person_role.role=3" in the > where. It doe

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread John McCawley
I just noticed, also goofy is your ", person_role" in your from with no criteria. I would generally put the "person_role.person = person.id" as an INNER JOIN, and then only have the "person_role.role=3" in the where. It doesn't look like that's the specific problem, but I generally find that

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread John McCawley
It looks to me like your problem is that weird area where you alias your inner join as "t" and thenn inner join based on this alias. You're getting a cartesian product somewhere, as evidenced by the "rows=700" in your explain. I already deleted the old mail with your table structure, but tr

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
On Mon, Nov 21, 2005 at 11:45:34AM -0600, Bruno Wolff III wrote: > On Mon, Nov 21, 2005 at 05:40:10 -0800, > Bill Moseley <[EMAIL PROTECTED]> wrote: > > > > Here's where I'm missing something. Trying to do an outer join on > > to bring in the class row with its class_time column: > > You don't

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bruno Wolff III
On Mon, Nov 21, 2005 at 05:40:10 -0800, Bill Moseley <[EMAIL PROTECTED]> wrote: > > Here's where I'm missing something. Trying to do an outer join on > to bring in the class row with its class_time column: You don't say exactly why you are having a problem with this, but I think you would be b

[GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
I need to generate a table of teachers, and the count of classes they taught in the past and are scheduled to teach in the future. id | last_name | totalfuture_class_count | past_class_count -+--+--++- 3 | Smith |

RE: [GENERAL] SQL help...

2001-05-15 Thread Ryan Mahoney
LL, >"qa_id" int8 NOT NULL, >CONSTRAINT "user_answers_pkey" PRIMARY KEY ("ua_id") >); >CREATE INDEX "user_answers_qa_id_key" ON "user_answers" ("qa_id"); >CREATE INDEX "user_answers_question_id_key"

RE: [GENERAL] SQL help...

2001-05-15 Thread Alex Hochberger
"qa_id" int8 NOT NULL, CONSTRAINT "user_answers_pkey" PRIMARY KEY ("ua_id") ); CREATE INDEX "user_answers_qa_id_key" ON "user_answers" ("qa_id"); CREATE INDEX "user_answers_question_id_key" ON "user_answers" (&q

Re: [GENERAL] SQL help...

2001-05-15 Thread Ryan Mahoney
Please post the sql statement that creates these tables. -r At 12:15 AM 5/16/01 -0400, Alex Hochberger wrote: >To any SQL wizards out there, > >I have finally exhausted my SQL knowledge. > >I have 3 tables that I need to do a fancy join on... > >1 stores the users >1 stores the questions >1 sto

[GENERAL] SQL help...

2001-05-15 Thread Alex Hochberger
To any SQL wizards out there, I have finally exhausted my SQL knowledge. I have 3 tables that I need to do a fancy join on... 1 stores the users 1 stores the questions 1 stores the user's answers to the questions (based on foreign keys to the answers table) I would like to create a result with

[GENERAL] SQL HELP

2000-03-09 Thread "Esperon, Juan Martín"
Hello, I need your help I have three question and I need you could respond me please. One of my questions is, how can take data that I have in Visual Basic to use it in an sql statement like for example in the SELECT function? The other question is, how can I execute a saved query with an sql

[GENERAL] SQL Help

1998-10-06 Thread anil
Hello! I have a tabe : addates : (adid int 4,rundate date,posted boolean,dateid int4 unique create no. from sequence datesequence) table is like this adid rundate posteddateid 1031 05-17-199