Re: [SQL] selecting records X minutes apart

2011-06-05 Thread Masaru Sugawara
(SELECT a2.id, a2.ts as ts_p, min(b2.ts) AS ts_c FROM tbl AS a2, tbl AS b2 WHERE a2.id = b2.id AND a2.ts + interval'5 minute' <= b2.ts GROUP BY a2.id, a2.ts UNION ALL SELECT a3.id, a3.ts, null FROM tbl AS a3 ) AS t2 ON t1.id = t2.id AN

Re: [SQL] selecting records X minutes apart

2011-06-05 Thread Masaru Sugawara
On Fri, 3 Jun 2011 15:52:53 -0400 lists-pg...@useunix.net wrote: I also think you might want to use WITH RECURSIVE clause. This SQL searches the case of an interval of 5 minutes or more, and sets a relationship between a parent to its child. CREATE TABLE tbl(id integer, ts time) ; INSERT INTO

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, cas

Re: [SQL] query optimization question

2002-11-08 Thread Masaru Sugawara
On Thu, 07 Nov 2002 09:57:27 +0100 Christoph Haller <[EMAIL PROTECTED]> wrote: > > ORDER BY proj.project_id ; > > What about simply replacing ORDER BY proj.project_id ; by > GROUP BY project_id, marketing_name ; You're right. Thanks a lot.

Re: [SQL] query optimization question

2002-11-06 Thread Masaru Sugawara
'GGH') AS proj, lots WHERE dt.lot_id = lots.lot_id AND lots.division_id = proj.division_id AND lots.project_id = proj.project_id AND dt.deficiency_status_id = ds.deficiency_status_id AND NOT EXISTS (SELECT 1 FROM menu_group_projects WHERE men

Re: [SQL] query optimization question

2002-11-06 Thread Masaru Sugawara
ts.project_id = proj.project_id AND dt.deficiency_status_id = ds.deficiency_status_id AND NOT EXISTS (SELECT 1 FROM menu_group_projects WHERE menu_code = 'WA' AND division_id = proj.division_id AND project_id = proj.project_id AND status = 'I') ORDER BY proj.project_id Regards, Masaru Sugawara ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] the best way to get the topest 3 record in every group

2002-09-09 Thread Masaru Sugawara
, purchase_date DESC ) AS t4 LIMIT ALL ) AS t5 WHERE t3.item_no = t5.item_no AND t3.supplier = t5.supplier AND t5.i - t3.n + 1 <= 3 ; Regards, Masaru Sugawara ---(end of broadcast)--- TIP 3: if posting/reading through

Re: [SQL] Need Help for select

2002-08-14 Thread Masaru Sugawara
) AS t2 GROUP BY t2.a_id, t2.d_id, t2.n HAVING COUNT(*) = t2.n ) AS t3, a, d WHERE a.id = t3.a_id AND d.id = t3.d_id Regards, Masaru Sugawara ---(end of broadcast)--- TIP 3: if posting/reading through Usenet,

Re: [SQL] Need Help for select

2002-08-14 Thread Masaru Sugawara
; > > > > > SELECT a.name, d.name > > FROM (SELECT DISTINCT min(b.a_id) AS a_id, c.d_id > > FROM b, c > >WHERE b.c_id = c.b_id > > GROUP BY b.c_id, c.d_id > > ) AS t, > > a, > > d > > WHERE a.id = t.a_

Re: [SQL] parser: parse error at or near "$1"

2002-08-14 Thread Masaru Sugawara
_code from >status_log where schedule_id =schedule_id order by complete_time desc ; PostgreSQL doesn't have a TOP keyword. You'll need to use a LIMIT keyword. See docs. http://www.postgresql.org/idocs/index.php?sql-select.html Regards, Masaru Sugawara ---

Re: [SQL] Need Help for select

2002-08-14 Thread Masaru Sugawara
d FROM b, c WHERE b.c_id = c.b_id GROUP BY b.c_id, c.d_id ) AS t, a, d WHERE a.id = t.a_id AND d.id = t.d_id Regards, Masaru Sugawara ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please

Re: [SQL] [HACKERS] please help on query

2002-07-17 Thread Masaru Sugawara
indices like the following? If not so, could you execute EXPLAIN ANALYZE after creating the indices. create index idx_lineitem_orderkey on lineitem(orderkey); create index idx_orders_orderkey on orders(orderkey); create index idx_orders_custkey on orders(custkey); cre

Re: [SQL] [HACKERS] please help on query

2002-07-15 Thread Masaru Sugawara
rkey) WHERE orders.orderkey IS NOT NULL GROUP BY orders.orderkey HAVING SUM(lineitem.quantity) > 300 ) AS t1 LEFT OUTER JOIN orders AS t2 USING(orderkey) ORDER BY t2.custkey

Re: [SQL] [HACKERS] please help on query

2002-07-14 Thread Masaru Sugawara
the following query take in your situation, and how many rows does it retrieve ? EXPLAIN ANALYZE SELECT lineitem.orderkey FROM lineitem GROUP BY lineitem.orderkey HAVING SUM(lineitem.quantity) > 300; Regards, Masaru Sugawara ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] Calculating with sql

2002-06-27 Thread Masaru Sugawara
average FROM tracks, albums WHERE tracks.DISCID = albums.DISCID GROUP BY albums.DISCID, albums.LENGTH ) AS mx ) ) AS a1 Regards

Re: [SQL] 2 Selects 1 is faster, why?

2002-06-27 Thread Masaru Sugawara
which is much faster. You are right. And this type of optimising are not yet implemented. Tom said it in the prior discussions. Regards, Masaru Sugawara ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropr

Re: [SQL] Identifying obsolete values

2001-10-22 Thread Masaru Sugawara
AND o.sid = t.sid AND o.entrancetime = MAX(t.entrancetime) ) ; By the way, a mail server have been downed ? Regards, Masaru Sugawara ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] Why would this slow the query down so much?

2001-10-17 Thread Masaru Sugawara
UERY PLAN might decrease. However, this trial may be a vain effort. I can't expect the result of the QUERY PLAN. :-) The indices: "stories_source", "stories_unique_story", and "stories_urn_key" Regards, Masaru Sugawara ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] MEDIAN as custom aggregate?

2001-10-13 Thread Masaru Sugawara
select (count(*)+1)/2 from ages) and a1.rank <= (select count(*)/2+1 from ages) ) ; Regards, Masaru Sugawara ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] challenging query

2001-10-06 Thread Masaru Sugawara
and u1.c = u0.c ) ; a | b | c | d ---+-++- 2 | BAR | Z2 | 101 2 | FOO | A1 | 101 3 | FOO | A1 | 102 4 | BAR | Z2 | 99 7 | BAR | ZY | 105 7 | FOO | AB | 105 (6 rows) Have a nice weekend! -- Masaru Sugawara ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Re: [SQL]plpgsql function case statement

2001-09-26 Thread Masaru Sugawara
Peter Schmidt wrote: >I'm having trouble finding the best solution for the following plpgsql >function. >The function does the following: Hi, I post in this mailing list for the first time. :-) I think your pl/pgsql function runs properly, but there is likely to exist another SQL pattern. In