Re: [SQL] obtaining difference between minimum value and next in size

2010-11-18 Thread Oliveiros d'Azevedo Cristina
- Original Message - From: Oliveiros d'Azevedo Cristina To: John Lister ; pgsql-sql@postgresql.org Sent: Wednesday, November 17, 2010 4:09 PM Subject: Re: [SQL] obtaining difference between minimum value and next in size Hi, John. I am not familiar with the func

Re: [SQL] "compressing" consecutive values into one

2010-11-23 Thread Oliveiros d'Azevedo Cristina
Salut, Louis-David, Can you please state the columns belonging to price table and give a concrete example? Say, data before and data after you want to do? Thank you A bien-tôt, Oliveiros - Original Message - From: "Louis-David Mitterrand" To: Sent: Tuesday, November 23,

Re: [SQL] group by hour + distinct

2010-11-26 Thread Oliveiros d'Azevedo Cristina
Howdy, Michelle, If you write something like this, SELECT hour , COUNT(id_user) as count FROM ( SELECT EXTRACT(hour from my_date) as hour, id_user FROM michelle GROUP BY EXTRACT(hour from my_date),id_user )subquery GROUP BY hour for each hour it will count the number of distinct user_id's ther

Re: [SQL] group by hour + distinct

2010-11-26 Thread Oliveiros d'Azevedo Cristina
Ciao * Olá! for each hour it will count the number of distinct user_id's there are . If I understood correctly what you need... Can you please test it and see if it is OK for your needs? With me, it worked on the sample data you provided Yes! Simply perfect! * Great to hear it worked

Re: [SQL] Insert row in 1.10.1 and 1.10.3

2010-11-26 Thread Oliveiros d'Azevedo Cristina
Could you please include the full insert SQL statement? Best, Oliveiros - Original Message - From: "ndias" To: Sent: Friday, November 26, 2010 4:22 PM Subject: [SQL] Insert row in 1.10.1 and 1.10.3 Hello to all, I have a question regarding the behavior of insert row

Re: [SQL] return records with more than one occurrences

2011-01-07 Thread Oliveiros d'Azevedo Cristina
Howdy, Tarsis. Please try this out. SELECT a.id, id_table1,a.name FROM "Table2" a NATURAL JOIN (SELECT id_table1 "Table2" GROUP BY id_table1 HAVING COUNT(*) > 1) b Tell me if it worked or not, and if it didn't the errors/uncorrect results. Best, Olive

Re: [SQL] how to get row number in select query

2011-01-26 Thread Oliveiros d'Azevedo Cristina
Hi, Lu Ying. How do you define which row is #1 ? And #2 ? E.g. Ordered by lname? Or gname...? Best, Oliveiros - Original Message - From: "Emi Lu" To: Sent: Wednesday, January 26, 2011 4:11 PM Subject: [SQL] how to get row number in select query Good morning, For

Re: [SQL] how to get row number in select query

2011-01-26 Thread Oliveiros d'Azevedo Cristina
version 8.3 doesn't have any "non-standard SQL" way to get a row number, but it is possible that something like that has been introduced in later versions... Best, Oliveiros - Original Message - From: "Emi Lu" To: Sent: Wednesday, January 26, 2011 4:11 PM

Re: [SQL] how to get row number in select query

2011-01-27 Thread Oliveiros d'Azevedo Cristina
Hi Oliveiros, Howdy! If it is to order in ascendent fashion by, say, lname, one possibility would be SELECT COUNT(b.*) as row_number, a.lname,a.gname FROM "Table1" a, "Table2" b WHERE a.lname >= b.lname GROUP BY a.lname,a.gname ORDER BY row_number If you want

Re: [SQL] Get days between two dates?

2011-01-31 Thread Oliveiros d'Azevedo Cristina
Doesn't the SELECT you indicated do what you need? Best, Oliveiros - Original Message - From: "Emi Lu" To: Sent: Monday, January 31, 2011 3:50 PM Subject: [SQL] Get days between two dates? Good morning, Is there an existing method to get days between two date

Re: [SQL] Get days between two dates?

2011-01-31 Thread Oliveiros d'Azevedo Cristina
That's precisely what I think.. :-| - Original Message - From: "Kenneth Marshall" To: "Emi Lu" Cc: Sent: Monday, January 31, 2011 4:39 PM Subject: Re: [SQL] Get days between two dates? On Mon, Jan 31, 2011 at 10:50:43AM -0500, Emi Lu wrote: Good morning, Is there an existing me

Re: [SQL] data import: 12-hour time w/o AM/PM

2011-02-08 Thread Oliveiros d'Azevedo Cristina
Howdy, Tarlika. If the data doesn't bring the AM/PM how are you supposed to distinguish between,say, 10pm and 10am ? Does it always start at 10:30am? So 10am never arises? Best, Oliveiros - Original Message - From: "Tarlika Elisabeth Schmitz" To: Sent: Tuesday, Fe

Re: [SQL] How to realize ROW_NUMBER() in 8.3?

2011-04-20 Thread Oliveiros d'Azevedo Cristina
version... Best, Oliveiros - Original Message - From: "Emi Lu" To: Sent: Wednesday, April 20, 2011 4:45 PM Subject: [SQL] How to realize ROW_NUMBER() in 8.3? Hello, ROW_NUMBER() is only ready in 8.4. For 8.3, is there a simple way to get row_number select row_number(),

Re: [SQL] need help with some aggregation magic

2011-06-09 Thread Oliveiros d'Azevedo Cristina
;t be overlapping, right? Best, Oliveiros - Original Message - From: "Andreas" To: Sent: Thursday, June 09, 2011 2:43 PM Subject: [SQL] need help with some aggregation magic hi, I have a log-table that stores events of users and projects like this ( user_id integer, project

Re: [SQL] Merge overlapping time-periods

2011-06-15 Thread Oliveiros d'Azevedo Cristina
Howdy, Marcel, In the example output you provided the ID = 2 should have just one record...Ain't I right? Best, Oliveiros - Original Message - From: Jira, Marcel To: 'pgsql-sql@postgresql.org' Sent: Wednesday, June 15, 2011 4:23 PM Subject: [SQL] Merge o

Re: [SQL] Merge overlapping time-periods

2011-06-15 Thread Oliveiros d'Azevedo Cristina
(IMHO) as much as 1 2000-01-01 2000-03-31 1 2000-04-01 2000-05-31 are. Isn't my understanding correct? Best, Oliveiros (SELECT x."ID",x."BEG",x."END" FROM mytable x LEFT JOIN ( SELECT a."ID" as xid ,a."BEG" as xbeg,a."END&

Re: [SQL] [NOVICE] Compare rows

2011-07-14 Thread Oliveiros d'Azevedo Cristina
- Original Message - From: LALIT KUMAR To: Oliveiros d'Azevedo Cristina Hi, I do have order of rows. The problem originally is: I need to set all flag with value 0 to -1 whose next row has flag as 1. This is to be done for each city separetly, i.e. flag of last r

Re: [SQL] Mysterious column "name"

2011-08-09 Thread Oliveiros d'Azevedo Cristina
Strange... Tables have hidden columns but AFAIK, "name" is not one of them... http://www.postgresql.org/docs/9.0/interactive/ddl-system-columns.html Best, Oliveiros - Original Message - From: "Nikolay" To: Sent: Thursday, August 04, 2011 3:50 PM Subject: [SQ

Re: [SQL] Using variables in select

2011-08-12 Thread Oliveiros d'Azevedo Cristina
like you need a function something like CREATE FUNCTION customer_table(int) RETURNS customer_table AS $$ SELECT COUNT(DISTINCT costumer_id),AVG(price) FROM customer_table WHERE productid = $1 $$ LANGUAGE SQL; HTH Best, Oliveiros - Original Message - From: "tlund79"

Re: [SQL] Add one column to another

2011-08-25 Thread Oliveiros d'Azevedo Cristina
Something like this...? SELECT first_name,surname, email1 || ';' || email2 FROM t_your_table; Best, Oliver - Original Message - From: "gvim" To: "pgsql sql" Sent: Thursday, August 25, 2011 3:21 PM Subject: [SQL] Add one column to another I have to deal with a table which contain

Re: [SQL] how to temporally disable foreign key constraint check

2011-10-21 Thread Oliveiros d'Azevedo Cristina
Something like ALTER TABLE t_yourtable DROP CONSTRAINT and then ALTER TABLE t_yourtable ADD FOREIGN KEY ? Best, Oliveiros - Original Message - From: "Emi Lu" To: Sent: Friday, October 21, 2011 2:36 PM Subject: [SQL] how to temporally disable foreign key constraint che

Re: [SQL] Self-Join

2011-12-06 Thread Oliveiros d'Azevedo Cristina
't scale well if you have many more items beyond three... Best, Oliveiros - Original Message - From: Abhinandan Raghavan To: pgsql-sql@postgresql.org Sent: Tuesday, December 06, 2011 1:57 PM Subject: [SQL] Self-Join Hi, I'm looking to frame an SQL statement

Re: [SQL] Self-Join

2011-12-06 Thread Oliveiros d'Azevedo Cristina
I have not. I've already skimmed through it. Indeed, it is very interesting Thanx , Scott Best, Oliver - Original Message - From: "Scott Swank" To: "Oliveiros d'Azevedo Cristina" Cc: "Abhinandan Raghavan" ; Sent: Tuesday, December 06, 2

Re: [SQL] update column

2012-02-10 Thread Oliveiros d'Azevedo Cristina
UPDATE admin SET parent = SUBSTR(id,1,4); Doesn't it do what you want? Best, Oliveiros - Original Message - From: "ssylla" To: Sent: Thursday, February 09, 2012 1:58 AM Subject: [SQL] update column Dear list, sorry, I already posted this, but it did not se

Re: [SQL] Another constant in foreign key problem.

2012-02-22 Thread Oliveiros d'Azevedo Cristina
two cents Best, Oliveiros I've googled this but can't find a suitable solution. Can anyone help please. -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to you

Re: [SQL] Aggregate and join problem

2012-03-01 Thread Oliveiros d'Azevedo Cristina
here. You'll have to substitute my col1, col2, etc with your actual column names. Best, Oliveiros SELECT query1.t1_id, t1.col2,t1.col3,t1.col4, query1.minimum FROM ( SELECT t3.col2 as t1_id, MIN(t2.col2) as minimum FROM Table_3 t3 JOIN Table_2 t2 ON t3.col1 = t2.col1 GROUP BY t3.col2 ) query1 JO

Re: [SQL] Aggregate and join problem

2012-03-01 Thread Oliveiros d'Azevedo Cristina
Great to Hear! Best, Oliver - Original Message - From: Swärd Mårten To: Oliveiros d'Azevedo Cristina ; pgsql-sql@postgresql.org Sent: Thursday, March 01, 2012 11:01 AM Subject: Re: [SQL] Aggregate and join problem It worked like a charm! Many thanks for that

Re: [SQL] How change col name during query to use it in where clause

2012-05-04 Thread Oliveiros d'Azevedo Cristina
I'm affraid you can't. AFAIK, WHERE clause is processed before the SELECT output expressions Best, Oliveiros - Original Message - From: "Marcel Ruff" To: Sent: Friday, May 04, 2012 11:25 AM Subject: [SQL] How change col name during query to use it in where

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Oliveiros d'Azevedo Cristina
Gary, You describe two tables vehicle stock and tax requests. The former has a one-to-many relationship wit the second one, right? But your query involves stock details and used_diary. What is the relationship of these two new tables to the previous ones? Could you please kindly supply an ex

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Oliveiros d'Azevedo Cristina
09:15:31.569471 | 42363 | 2012-05-16 (2 rows) On Wednesday 23 May 2012 10:37:31 Oliveiros d'Azevedo Cristina wrote: Gary, You describe two tables vehicle stock and tax requests. The former has a one-to-many relationship wit the second one, right? But your query involves stock details and used_diar

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Oliveiros d'Azevedo Cristina
= u.ud_pex_registration where s_stock_no = 'UL15470'; GROUP s_stock_no,s_regno,s_vin,s_created ) subq JOIN used_diary sec ON subq.m = sec.ud_id Best, Oliver - Original Message - From: "Oliveiros d'Azevedo Cristina" To: "Gary Stainburn" ; Sent: Wednesday, May 23, 20

Re: [SQL] left outer join only select newest record

2012-05-24 Thread Oliveiros d'Azevedo Cristina
Hi, Gary, Unless I'm mistaken this didn't give what you need. Could you please tell me (if you have time) the error returned or wrong result, just for my own understanding of where I've gone sideways on this...? Best, Oliver - Original Message - From: "Oliveiro

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
Hi, Mike, Can you tell me if this gives what you want, and if it doesn't, what is the error reported, or wrong result ? This is untested query, so Im not sure about it. Best, Oliver SELECT make, model, color,type, subquery1.cpp, min(cost/yield) as cpp2 ( SELECT printers.make, printers.model,

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
2.make,subquery2. model, subquery2.color,subquery2.type,subquery1.cpp ORDER BY make, model; - Original Message - From: "Oliveiros d'Azevedo Cristina" To: "Relyea, Mike" ; Sent: Friday, June 01, 2012 3:56 PM Subject: Re: [SQL] Lowest 2 items per Hi, Mike, Can you

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
Oliver, I had to make a few grammatical corrections on your query to get it to run, but once I did it gave me almost correct results. It leaves out all of the printer models that only have one consumable with a cost. Some printers might have more than two black inks and some might have only one

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
I only made grammatical changes necessary for the query to function (adding a missing FROM, fully qualifying "SELECT Make" as " SELECT subquery2.Make", etc.) I tried changing the join type to right and left but that did not have the desired result. * I see... If we add a query with a union tha

Re: [SQL] generated dates from record dates - suggestions

2012-08-20 Thread Oliveiros d'Azevedo Cristina
With a CASE ... WHEN statement? Best, Oliver - Original Message - From: "Gary Stainburn" To: Sent: Monday, August 20, 2012 1:17 PM Subject: [SQL] generated dates from record dates - suggestions Hi folks. I've got a table with three dates which are populated from an external sour

Re: [SQL] Disabling constraint check

2012-09-17 Thread Oliveiros d'Azevedo Cristina
Have you tried this ALTER TABLE table_name DROP CONSTRAINT constraint_name; Best, Oliveiros - Original Message - From: "Salomao Domingos" To: Sent: Monday, September 17, 2012 7:58 PM Subject: [SQL] Disabling constraint check Hi, I'm need to import data to PostgreS

Re: [SQL] complex query

2012-10-28 Thread Oliveiros d'Azevedo Cristina
Hi, Scott. I'd like to kick in this thread to ask you some advice, as you are experienced in optimizing queries. I also use extensively joins and unions (less than joins though). Anyway, my response times are somewhat behind miliseconds, they are situated on seconds range, and sometimes they ex

<    1   2