Re: [SQL] generate a range within a view

2013-10-10 Thread Gary Stainburn
|80 | 2013-10-10 | 4 | 8 H|80 | 2013-10-11 | 5 | 3 H|80 | 2013-10-12 | 6 | 2 (7 rows) goole=# -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@post

[SQL] generate a range within a view

2013-10-10 Thread Gary Stainburn
he -- standard week create table site_user_department_date_limit ( s_idchar not null, de_id int4 not null, de_date date not null, day_limit int4 not null CHECK (day_limit >= 0), primary key (s_id,de_id, de_date), foreign key (s_id, de_id) references site_user

Re: [SQL] unique key problem on update

2013-09-20 Thread Gary Stainburn
e text, > primary key (sp_id) deferrable > ); Cheers. I'll look at that. It's actually the second unique index that's the problem but I'm guessing I can set that index up as deferrable too. Hopefully it'll work for mysql too. -- Gary Stainburn Group I.T. Manager Rin

[SQL] unique key problem on update

2013-09-20 Thread Gary Stainburn
I get round this. Also, the final version will be put onto a WordPress web site which means I will have to port it to MYSQL which I don't know, so any solution that will work with both systems would be a great help. Ta Gary stainburn=# \d skills_pages

Re: [SQL] value from max row in group by

2013-07-26 Thread Gary Stainburn
roup by stts_id; > > another simple solution with distinct on: > > select distinct on (stts_id, stts_offset) stts_id, > stts_offset+stts_duration from table > order by stts_id, stts_offset desc > > Marc Mamin > -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ri

Re: [SQL] value from max row in group by

2013-07-25 Thread Gary Stainburn
As usual, once I've asked the question, I find the answer myself. However, it *feels* like there should be a more efficient way. Can anyone comment or suggest a better method? timetable=> select stts_id, stts_offset+stts_duration as total_duration timetable-> from standard_trip_sections timeta

[SQL] value from max row in group by

2013-07-25 Thread Gary Stainburn
Hi folks, I need help please. I have a table of trip section details which includes a trip ID, start time as an offset, and a duration for that section. I need to extract the full trip duration by adding the highest offset to it's duration. I can't simply use sum() on the duation as that would

[SQL] unique keys / foreign keys on two tables

2012-11-29 Thread Gary Stainburn
have other tables that refer to *destinations* which will be an ID that could be either an extension or a group. Examples are 'Direct Dial In' numbers which could point to either. How would I do that? -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk

Re: [SQL] pull in most recent record in a view

2012-10-28 Thread Gary Stainburn
st_id join skills k on k.sk_id = q.sk_id; -- 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] pull in most recent record in a view

2012-10-28 Thread Gary Stainburn
n staff t on t.st_id = q.st_id join skills k on k.sk_id = q.sk_id order by st_id, sk_id I am still at the concept stage for this project so I can change the schema if required -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sq

Re: [SQL] weird join producing too many rows

2012-09-12 Thread Gary Stainburn
le rows in pieces_requests with the same p_id, r_id pairing? > Your join must be resulting in multiple rows for each p_id somehow. > -- 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] weird join producing too many rows

2012-09-12 Thread Gary Stainburn
4900 | ESALES4 | 4197 | WSERV1 | 2731 | LSALESE | (33 rows) users=# -- 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 your subscription: http://www.post

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

2012-08-22 Thread Gary Stainburn
on, but I'm wondering how I would include this is the select / view . Gary -- 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

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

2012-08-21 Thread Gary Stainburn
that a typo? if not how am i to interpret > it? The table contains date_1, date_2 and date_3. The resulting view needs to contain date_1, date_2, date_3, date_a and date_b where date_a and date_b are calculated based on the first three (plus a text field). -- Gary Stainburn Group I.T. Manager Rin

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

2012-08-21 Thread Gary Stainburn
was what I was wondering, and was looking for suggestions / best practices on how to do this. I had first thought of embedding case/when statements in the view but it could easily become unweildy -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pg

[SQL] generated dates from record dates - suggestions

2012-08-20 Thread Gary Stainburn
date_1 > date3 rhen date_b=date1 else date_b=date2 etc. What's the best way to do this? I know it's a quite open question but I'm interested to hear different responses -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via

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

2012-05-24 Thread Gary Stainburn
On Thursday 24 May 2012 09:17:00 Pavel Stehule wrote: > please, WHERE (ud_id, ud_pex_registration) = (SELECT ... > > replace by > > WHERE (..) IN (SELECT .. > > Regards > > Pavel Worked perfectly, thank you -- Gary Stainburn Group I.T. Manager Ringways Garage

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

2012-05-23 Thread Gary Stainburn
On Wednesday 23 May 2012 10:46:02 Pavel Stehule wrote: > select distinct on (s.s_registration) * > ... order by u.ud_id desc I tried doing this but it complained about the order by. goole=# select distinct on (s.s_stock_no) s_stock_no, s_regno, s_vin, s_created, ud_id, ud_handover_date from sto

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

2012-05-23 Thread Gary Stainburn
and of the > desired output? For me it would be easier... > > Best, > Oliver > > - Original Message - > From: "Gary Stainburn" > To: > Sent: Wednesday, May 23, 2012 10:27 AM > Subject: [SQL] left outer join only select newest record > > > Hi f

[SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
gistration = u.ud_registration; -- 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Wrong output from union

2012-04-02 Thread Gary Stainburn
t; > http://www.postgresql.org/docs/9.0/interactive/sql-select.html > -- 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] Wrong output from union

2012-03-30 Thread Gary Stainburn
select u_id || ':' || rm_timestamp::date as key from request_reminders where u_id is not null and rm_timestamp>='2012-03-26' and rm_timestamp <= ('2012-03-26'::date + '7 days'::interval); key --- 25:2012-03-27 25

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

2012-02-23 Thread Gary Stainburn
ent_user_level shouldn't have a field named fl_f_id, to > identify which facility the document/folder belongs to? > Had it such a field, you could do something like > FOREIGN_KEY (fl_f_id,fl_level) REFERENCES facility_levels (fl_f_id, > fl_level) > > > Just my two cents

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

2012-02-22 Thread Gary Stainburn
le storing only facility_levels for > fl_f_id 22. The foreign key would reference the child table and not > facility_levels. Everything in the child table would also exist in > facility_levels. As this is so specific to PostgreSQL and is not hugely > common as a technique, read this as

[SQL] Another constant in foreign key problem.

2012-02-22 Thread Gary Stainburn
s 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] date range to set of dates expansion

2012-01-20 Thread Gary Stainburn
ick to using RPM's. Can I upgrade to 9.1 on a FC9 system using RPM's? Also, the last time I did a server upgrade (FC4 to the FC9 system) upgrading apache, PHP and postgresql broke so many things in my applications it was painful. Can anyone suggest ways I can soak test my systems

Re: [SQL] SOLVED - date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
Sorry for using the list as a scratch-pad for my brain. select aid, asid, generate_series(asdate-'1970-01-01'::date, afdate-'1970-01-01'::date)+'1970-01-01'::date as adate, acomments from availability; Has done the trick. -- Gary Stainburn Group I.T.

Re: [SQL] date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
called in context that cannot accept a set CONTEXT: PL/pgSQL function "date_range" line 4 at RETURN NEXT Is there a way to use the integer only generate_series in 8.3 to generate dates by typecasting to/from integers? -- Gary Stainburn Group I.T. Manager Ringways Ga

Re: [SQL] date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
On Thursday 19 January 2012 15:11:46 Gary Stainburn wrote: > I'll be upgrading my live server as soon as possible, but in the meantime > can anyone suggest a way I can do the same thing using Postgresql 8.1 > until I can evaluate 8.4 on my live systems? Sorry, I meant 8.3 as my c

Re: [SQL] date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
g using Postgresql 8.1 until I can evaluate 8.4 on my live systems? -- 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 your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] date range to set of dates expansion

2012-01-18 Thread Gary Stainburn
date+1; while wdate <= tdate LOOP return next wdate; wdate:=wdate+1; end LOOP; return; END; $$ LANGUAGE plpgsql; -- 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

Re: SOLVED - [SQL] foreign keys and lots of tables

2011-05-19 Thread Gary Stainburn
anyway. Gary On Thursday 19 May 2011 01:09:07 David W Noon wrote: > On Wed, 18 May 2011 20:10:19 +0100, Gary Stainburn wrote about [SQL] > > foreign keys and lots of tables: > >I have the following tables (individual seat allocation removed to > >make it simpler) > >

[SQL] foreign keys and lots of tables

2011-05-18 Thread Gary Stainburn
bookings table and I don't know how. To complicate things, when the initial booking is made, bot c_id and c_seat are NULL. Will this make any difference? Gary -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsq

Re: [SQL] foreign key question

2011-01-05 Thread Gary Stainburn
On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote: > Now I want to set up a new access level table specific to the itinerary, > along the lines of > > u_id int4 not null references users(u_id) > fl_level int4 not null references facility_levels(16, fl_level) > > Firs

[SQL] foreign key question

2011-01-05 Thread Gary Stainburn
(u_id) fl_level int4 not null references facility_levels(16, fl_level) Firstly, is this possible, and secondly how would I do it? -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

Re: [SQL] create function problem

2010-12-30 Thread Gary Stainburn
On Thursday 30 December 2010 17:47:09 Adrian Klaver wrote: > To follow up I think the OP was looking for ELSEIF not ELSE IF. Changing > the ELSE IF to ELSEIF should fix it. > Thanks guys. That'll teach me to read tutorials more carefully. -- Gary Stainburn I.T. Manager Ringway

[SQL] create function problem

2010-12-30 Thread Gary Stainburn
LL; END IF; IF eta > req_date THEN RETURN eta; END IF; RETURN req_date; END; $$ LANGUAGE 'plpgsql'; [r...@stan t-cards]# -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make chan

Re: [SQL] Slow response in select

2010-09-21 Thread Gary Stainburn
On Tuesday 21 September 2010 15:20:15 Gary Stainburn wrote: > > I've posted th explain analyze at > > http://www1.ringways.co.uk/explain_analyse.txt > > I've marked a line with a sort in that appears to be the bit that's taking > the time. Am I right? > I&

Re: [SQL] Slow response in select

2010-09-21 Thread Gary Stainburn
On Tuesday 21 September 2010 15:11:09 Craig Ringer wrote: > On 09/21/2010 08:25 PM, Gary Stainburn wrote: > > Hi folks,I have a view that seems to be very slow compared to similar > > views on the same server. > > > > I've had a look at running explain

[SQL] Slow response in select

2010-09-21 Thread Gary Stainburn
w on a database that has been live for some time but I've never managed to get to the bottom of why it's much slower than the other views. Gary -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties fo

Re: [SQL] simple (?) join

2009-09-28 Thread Gary Stainburn
.o_id >LEFT JOIN orders_log ol > ON ol.o_id=o.o_id > AND ol.ol_timestamp=max_olt.maxts > ; Cheers Jim, That worked. Gary -- Gary Stainburn Gary's Haircut 700 Please visit http://www.justgiving.com/Gary-Stainburn/ to help me raise money for Canc

Re: [SQL] simple (?) join

2009-09-28 Thread Gary Stainburn
d it's associated user - i.e. who made the the last log entry and when. I suppose I'm asking how I would do the sub-query to pull the most recent log entry per order. -- Gary Stainburn Gary's Haircut 700 Please visit http://www.justgiving.com/Gary-Stainburn/ to help me raise mone

[SQL] simple (?) join

2009-09-24 Thread Gary Stainburn
? Cheers -- Gary Stainburn Gary's Haircut 700 Please visit http://www.justgiving.com/Gary-Stainburn/ to help me raise money for Cancer Research - in return I'll have my head shaved -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscrip

Re: [SQL] simple join is beating me

2009-07-13 Thread Gary Stainburn
y.o_date , orders, delivery > FROM (/* ur first query here */) ordersQuery > NATURAL RIGHT JOIN (/* ur second query goes here */) deliveryQuery > ORDER BY deliveryQuery.o_date DESC > > Tararabite, > > Oliveiros > @Allgarve > > > > 2009/7/13 Gary Stainburn >

[SQL] simple join is beating me

2009-07-13 Thread Gary Stainburn
4 |3 2009-07-09 | 5 |4 2009-07-08 | 12 |2 2009-07-07 | 5 |4 2009-07-06 | 2 |7 2009-07-03 | 2 |6 2009-07-02 | 7 |5 2009-07-01 | 19 |3 2009-06-30 | 20 |3 -- Gary Stainburn This emai

[SQL] update from join

2009-05-14 Thread Gary Stainburn
ved all vehicles with only one record. I seem to think I need an update. from. statement -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investig

Re: [SQL] Trigger/Function - one solution - was constraint question (I think)

2008-12-04 Thread Gary Stainburn
_id,ROWLENGTH; END IF; RETURN NEW; END; $proc$ LANGUAGE plpgsql; CREATE TRIGGER compound_bays_range_check BEFORE INSERT OR UPDATE on compound_bays FOR EACH ROW EXECUTE PROCEDURE compound_bays_range_check(); -- Gary Stainburn This email does not contain private or confidential material

[SQL] constraint question (I think)

2008-12-04 Thread Gary Stainburn
t4 not null ); alter table compound_bays add constraint compound_bays_row_check foreign key (co_id, cr_id) references compound_rows(co_id,cr_id); -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown

Re: [SQL] Quick select, slow update - help with performance problems

2008-07-01 Thread Gary Stainburn
On Tuesday 01 July 2008 12:17, Richard Huxton wrote: > Gary Stainburn wrote: > > update used_diary set > > ud_valet_completed=now(), ud_valet_completed_by=25 > > where ud_valet_completed is null and > > ud_valet_required < CURRENT_DATE-'

[SQL] Quick select, slow update - help with performance problems

2008-07-01 Thread Gary Stainburn
T_DATE-'7 days'::interval is still running after approx 1 1/2 minutes. I've noticed that other updates also seem to take a long time. Could I have any suggestions on how I could start looking into why this is. Could it be the config of postgresql, issues with my schema, or something

Re: [SQL] SOLVED - months, intervals and integers

2008-06-04 Thread Gary Stainburn
ts; On Wednesday 04 June 2008 09:44, Gary Stainburn wrote: > Hi folks > > I've got the following table and view and I don't know exactly how to get > what I want. > > The table contains integers for the number of months. > I want the view to convert those month inte

[SQL] months, intervals and integers

2008-06-04 Thread Gary Stainburn
s 6 I need start_date to be CURRENT_DATE-'6 months'::interval Any ideas? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 200

[SQL] performance issue - view and derived field

2008-02-08 Thread Gary Stainburn
e (ud_handover_date) "used_diary_reg_index" btree (ud_registration) "used_diary_required" btree (ud_required) "used_diary_stock_index" btree (ud_stock) "used_diary_ud_pex_valet_completed" btree (ud_pex_valet_completed) "used_diary_ud_valet_com

Re: [SQL] regex_replace problem -additional

2008-01-25 Thread Gary Stainburn
) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts. goole=# -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed pur

[SQL] regex_replace problem

2008-01-25 Thread Gary Stainburn
# rpm -qa|grep postgresql postgresql-jdbc-8.1.9-1.fc5 postgresql-libs-8.1.9-1.fc5 postgresql-pl-8.1.9-1.fc5 postgresql-contrib-8.1.9-1.fc5 postgresql-server-8.1.9-1.fc5 postgresql-docs-8.1.9-1.fc5 postgresql-python-8.1.9-1.fc5 postgresql-8.1.9-1.fc5 postgresql-test-8.1.9-1.fc5 postgresql-tcl-8.

[SQL] odd error updating - varchar

2007-12-14 Thread Gary Stainburn
', 'requests', 'UNSPECIFIED', 're_id', 'r_id') "RI_ConstraintTrigger_110469" AFTER UPDATE ON requests FROM recipients NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_upd"('', 'recip

Re: [SQL] calculation of pay based on dates

2007-07-13 Thread Gary Stainburn
triggers to call that function when > current date and antedate is equal... > > > > Any one can help on this... I need it very soon > > > Regards > Penchal > Surely this would easiest be done using a view rather than a trigger or function. Simply have the salary ca

Re: [SQL] select from table and add rows.

2007-07-06 Thread Gary Stainburn
On Friday 06 July 2007 16:02, Andrew Sullivan wrote: > On Fri, Jul 06, 2007 at 02:25:08PM +0100, Gary Stainburn wrote: > > This sets up an array with some pseudo values and then populates it with > > *proper* values from a table. > > > > How's the best way to

[SQL] select from table and add rows.

2007-07-06 Thread Gary Stainburn
ame" ) as $key=>$dets) { $wpartners[$key]=$dets; } This sets up an array with some pseudo values and then populates it with *proper* values from a table. How's the best way to do this all within SQL. -- Gary Stainburn This email does not contain privat

Re: [SQL] workday function

2007-05-15 Thread Gary Stainburn
attached the code for anyone who want to use or improve it. It should be fairly simple to write a function to use that dataset to ignore *non-working* days. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government part

[SQL] workday function

2007-05-15 Thread Gary Stainburn
7;ve found that MS Excel has a workday function which seems to do what I want. Any help would be appreciated. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulati

[SQL] select ..... not in .....

2007-05-14 Thread Gary Stainburn
t not return the row? select v_d_code, v_o_number, v_vin, v_status from vista_details where v_vin not in ( goole(# select substring(w_vin from '(.{11}$)') from walon); v_d_code | v_o_number | v_vin | v_status --++---+-- (0 rows) -- Gary Stainburn Thi

Re: [SQL] select slows from 3 seconds to 30 seconds

2007-05-08 Thread Gary Stainburn
On Saturday 05 May 2007 01:57, Tom Lane wrote: > Gary Stainburn <[EMAIL PROTECTED]> writes: > > I have the query below which when run takes approx 3 seconds. However > > when I add the condition 'and w_ws_id = 10' onto the end changes to 30+ > > seconds.

[SQL] select slows from 3 seconds to 30 seconds

2007-05-04 Thread Gary Stainburn
w_vin left outer join stock s on substring(s.s_vin from '(.{11}$)') = w_vin left outer join vista v on v.v_vin = w_vin where w_hide = 0. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unkn

[SQL] SOLVED - Another date range join problem

2007-04-05 Thread Gary Stainburn
1 | 2007-04-21 | 2007-04-22 | 2 | 0 | 2 1 | 28 | 2007-03-01 | 2007-03-01 | 1 | 0 | 1 2 | 28 | 2007-03-02 | 2007-03-07 | 6 | 0 | 6 (6 rows) -- Gary Stainburn This email does not contain private or confidential material as it may be sn

[SQL] Another date range join problem

2007-04-05 Thread Gary Stainburn
5 1 2007-04-11 4 6 1 2007-04-13 4 3 1 2007-04-14 5 5 1 2007-04-15 5 6 1 giving 1 1 2007-04-01 2007-04-01 1 2 1 2007-04-10 2007-04-15 4 -- Gary Stainburn This email does n

Solved - [SQL] best way: diary functions.

2007-04-04 Thread Gary Stainburn
overlaps (a.asdate,a.afdate) left join roster_staff r on r.rsdate = date_range; Can anyone see any problems or improvements to this? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and

[SQL] best way: diary functions.

2007-04-03 Thread Gary Stainburn
e) returns setof date AS $PROC$ DECLARE wdate date; BEGIN return next fdate; wdate:=fdate+1; while wdate <= tdate LOOP return next wdate; wdate:=wdate+1; end LOOP; return; END; $PROC$ LANGUAGE plpgsql; -- Gary Stainburn This email does not contain private or confid

Re: [SQL] join/group/count query.

2006-12-21 Thread Gary Stainburn
not do that. > Because the else is NULL, count does work. Although I would imagine sum will also work, count more reflects the logic, i.e. the number of times that condition is true -- Gary Stainburn This email does not contain private or confidential material as it may be snooped o

Re: [SQL] join/group/count query.

2006-12-20 Thread Gary Stainburn
0 | 2 |0 12| 12||13 |0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 5 | 6 |0 10| 10|rr Motor| 7 |0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 5 |0 34| 34|ff fff | 3 |0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 2 |0 102| 102| xxx| 1 |0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1

[SQL] join/group/count query.

2006-12-20 Thread Gary Stainburn
order_details where date_trunc('month',CURRENT_DATE) = date_trunc('month',o_ord_date) group by o_p_id, p_name; -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and

Re: [SQL] SELECT substring with regex

2006-07-07 Thread Gary Stainburn
x27;) as BASE_NAME, substring('150mm LD AD Asp XR Macro','^\\d+mm (.*)$') as SUFFIX; base_name | suffix ---+ 150mm | LD AD Asp XR Macro (1 row) The brackets surround the required match -- Gary Stainburn This email does not con

Re: [SQL] Update from join

2006-07-07 Thread Gary Stainburn
On Friday 07 July 2006 11:29, Gary Stainburn wrote: > I know this is probably a FAQ but Google etc hasn't helped. > > I have two tables, both with stock number and registration number in. > The second table always has the correct stock number, the first doesn't. > > I

[SQL] Update from join

2006-07-07 Thread Gary Stainburn
270 2591 | YF06OJM | NL | NL6351 2627 | YC06SGX | ND | ND9057 1795 | YC06SGX | ND | ND9057 2634 | YB06KHT | NL | NL6450 2620 | YF06ZKD | ND | ND9236 (21 rows) -- Gary Stainburn This email does not contain private or confi

Re: [SQL] select best price

2005-10-26 Thread Gary Stainburn
On Wednesday 26 October 2005 4:21 pm, Gary Stainburn wrote: > Hi folks > > I've got a table holding item code(cs_id), supplier a/c (co_id) , and > price (cs_price). > > How can I select the rows containing the lowest price for each item > code? > > I've tried v

[SQL] select best price

2005-10-26 Thread Gary Stainburn
Hi folks I've got a table holding item code(cs_id), supplier a/c (co_id) , and price (cs_price). How can I select the rows containing the lowest price for each item code? I've tried various forms of min() etc and know it must be simple but I'm stumped. Gary -- Gary Stainbu

[SQL] diary constraints

2005-08-23 Thread Gary Stainburn
, one for the start date/time and one for the return date/time. How do I go about creating constraints on inserts and updates to ensure that a) the finish is after the start b) two allocations for a single vehicle don't overlap. -- Gary Stainburn This email does not contain priva

Re: [SQL] Speed up slow select - was gone blind

2005-04-05 Thread Gary Stainburn
for the help anyway. Gary On Friday 01 Apr 2005 1:46 pm, you wrote: > Can you send the EXPLAIN ANALYZE of each? We can't really tell where > the slowdown is without that. > > On Apr 1, 2005 12:32 PM, Gary Stainburn <[EMAIL PROTECTED]> wrote: > > Hi folks. > > >

[SQL] Speed up slow select - was gone blind

2005-04-01 Thread Gary Stainburn
in plates pl on r.r_plates = pl.pl_id ORDER BY r.r_id; -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

Re: [SQL] gone blind - can't see syntax error

2005-04-01 Thread Gary Stainburn
On Friday 01 April 2005 1:01 pm, you wrote: > On Friday 01 Apr 2005 5:06 pm, Gary Stainburn wrote: > > Hi folks. > > > > I've been looking at this for 10 minutes and can't see what's > > wrong. Anyone care to enlighten me. > > comma after '

[SQL] gone blind - can't see syntax error

2005-04-01 Thread Gary Stainburn
s d on r.r_d_id = d.d_id, left outer join departments de on r.r_de_id = de.de_id, left outer join customers c on r.r_c_id = c.c_id, left outer join comment_tallies co on r.r_id = co.r_id ORDER BY r.r_id; psql:new-view.sql:19: ERROR: parser: parse error at or near "left" -- Gary Stainburn Th

Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Gary Stainburn
#x27; THEN 'A' ELSE owner END) WHERE owner IN ('A','B') > > Hello again. > > I've tried the first one but get a syntax error. Anyone see why? > > hardware=# update pieces set p_owner = (case if p_owner = 305 then > 724 else 305 end) where p_

Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Gary Stainburn
p_site = \'L\' where p_id = $1; > > update pieces set p_name = \'SPARE\', p_location = \'spare\', > p_site = \'L\' > where p_id = 2; > This isn't quite what I want. I want to SWAP the p_name and p_location between the two record

Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Gary Stainburn
get a syntax error. Anyone see why? hardware=# update pieces set p_owner = (case if p_owner = 305 then 724 else 305 end) where p_owner in (305, 724); ERROR: parser: parse error at or near "p_owner" hardware=# -- Gary Stainburn This email does not contain private or confi

[SQL] best way to swap two records (computer details)

2005-03-18 Thread Gary Stainburn
27;m not after someone to do my work for me, but a good starting point would be very much appreciated) -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regula

Re: [SQL] order by question

2005-03-09 Thread Gary Stainburn
On Wednesday 09 March 2005 1:06 pm, you wrote: > Gary Stainburn wrote: > > Hi folks. > > > > I seem to remember somewhere being shown how to bump specific rows > > to the top of a list; something along the lines of: > > > > select c_id as key, c_des as val

[SQL] order by question

2005-03-09 Thread Gary Stainburn
bumped to the top of the list, but instead appear in their correct position in the order by value part. Is it possible and if so how do I do it? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown

Re: [SQL] simple update from select ??

2005-03-07 Thread Gary Stainburn
rected version of a suggestion by Sean Davis update pieces set p_owner=piece_pieces.pp_id from piece_pieces where piece_pieces.pp_part=pieces.p_id; Under Sean's suggestion I did this inside a transaction block so I could check that it did what I wanted. -- Gary Stainburn This email does not

[SQL] simple update from select ??

2005-03-07 Thread Gary Stainburn
of owner pp_part -- id of owned -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Gary Stainburn
On Tuesday 16 November 2004 1:08 pm, sad wrote: > On Tuesday 16 November 2004 14:29, Gary Stainburn wrote: > > Hi folks. > > > > I'm looking at the possibility of implementing a photo gallery for > > my web site with a tree structure > > > > How wou

[SQL] tree structure photo gallery date quiery

2004-11-16 Thread Gary Stainburn
iddleton should return 1, 2004-01-01 09:12:12 and Root should return 4, 2004-11-10 12:12:00 -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Inves

Re: [SQL] curious delay on view/where

2004-10-28 Thread Gary Stainburn
On Thursday 28 October 2004 3:25 pm, Tom Lane wrote: > Gary Stainburn <[EMAIL PROTECTED]> writes: > > Anyone got any ideas of the cause, or thoughts on how I can trace > > the problem? > > EXPLAIN ANALYZE results for the fast and slow cases would be > interesting

Re: [SQL] extra info - curious delay on view/where

2004-10-28 Thread Gary Stainburn
On Thursday 28 October 2004 11:16 am, Gary Stainburn wrote: > Hi folks. > > I have the following view: > > CREATE VIEW "stock_available" as > SELECT * FROM stock_details > WHERE available = true AND visible = true AND > location not in (SELECT descr FROM ign

[SQL] curious delay on view/where

2004-10-28 Thread Gary Stainburn
t * from stock_available where branch != 'Doncaster' and select * from stock_available where branch != 'Leeds' which only return the equivelent of the top two (we only have Leeds and Doncaster) are les than 1 second. Anyone got any ideas of the cause, or thoughts on how I can tr

[SQL] table update using result from join

2004-10-11 Thread Gary Stainburn
# What I want is something like update requests set r_fuel=, r_c_id = 7 where r_c_id in (... -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regu

Re: [SQL] subselect prob in view

2004-06-22 Thread Gary Stainburn
On Monday 21 Jun 2004 4:11 pm, Gary Stainburn wrote: > On Monday 21 Jun 2004 3:19 pm, Tom Lane wrote: > > Gary Stainburn <[EMAIL PROTECTED]> writes: > > > from requests r, users u, request_types t, > > > request_states s, dealershi

Re: [SQL] subselect prob in view

2004-06-21 Thread Gary Stainburn
On Monday 21 Jun 2004 3:19 pm, Tom Lane wrote: > Gary Stainburn <[EMAIL PROTECTED]> writes: > > from requests r, users u, request_types t, > > request_states s, dealerships d, departments de, customers c > > left outer join (select co_r_id, c

[SQL] subselect prob in view

2004-06-21 Thread Gary Stainburn
sts" psql:goole1.sql:45: ERROR: JOIN/ON clause refers to "requests", which is not part of JOIN [EMAIL PROTECTED] gary]$ which at least makes sense. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government

solved Re: [SQL] view problem - too many rows out

2004-05-12 Thread Gary Stainburn
On Wednesday 12 May 2004 11:02 am, Gary Stainburn wrote: > Hi folks. > [snip] > create view order_summary as > select > c.cs_id, cs.count as qty, c.cs_make, c.cs_code, c.cs_type, > cst.cst_desc, c.cs_colour, > o.or_id, > o.or_supp, o.or_date

[SQL] view problem - too many rows out

2004-05-12 Thread Gary Stainburn
hardware=# -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---(end of

  1   2   >