Contractor UK Bulletin Board  PayStream

Go Back   Contractor UK Bulletin Board > Contractor UK Forums > Technical
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 2nd October 2008, 13:57   #31
Ruprect
Contractor Among Contractors
 
Ruprect's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 1,663
Default

OK Smarty pantses

how about this:

table "customer_snapshot"

fields customer_surname, customer_dob, snapshot_date, customer_email(other fields...)

for the purposes of this exercise customer_surname, customer_dob and snapshot_date are a composite PK.

What I want to know is:
1) which customers exist today that didn't exist yesterday and
2) which customers existed yesterday that don't exist today and
3) which customers have changed their email addresses since yesterday.

DB: Sybase, Number of records in table - about 2.5 million.
__________________
"Trouble with the French is they have no word for Entrepreneur"

Quote:
Originally Posted by Xenophon View Post
Ruprect is awarded +5 Xeno Geek Points.
...
*In addition, the following posters are awarded +15 Xeno Geek Points:
Ruprect
Ruprect is offline   Reply With Quote
Old 2nd October 2008, 14:16   #32
Spacecadet
Super poster
 
Spacecadet's Avatar
 
Join Date: Mar 2006
Location: Jupiter
Posts: 3,104
Default

use derived tables

Can't be arsed writing out the full SQL, you can do that yourself.
Heres a starter for 10 though
Quote:
select <stuff>
from (select * from customer_snapshot where date = <today>) as Today
full outer join
(select * from customer_snapshot where date = <yesterday>) as Yesterday
on today.<primary key fields> = yesterday.<primary key fields>
where
<add your where clauses here>
Spacecadet is offline   Reply With Quote
Old 2nd October 2008, 14:21   #33
Ruprect
Contractor Among Contractors
 
Ruprect's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 1,663
Default

Thanks I'll give it a go
__________________
"Trouble with the French is they have no word for Entrepreneur"

Quote:
Originally Posted by Xenophon View Post
Ruprect is awarded +5 Xeno Geek Points.
...
*In addition, the following posters are awarded +15 Xeno Geek Points:
Ruprect
Ruprect is offline   Reply With Quote
Old 2nd October 2008, 14:57   #34
Ruprect
Contractor Among Contractors
 
Ruprect's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 1,663
Default

One last qn - without a full outer join available to me in sybase is there any way to do this in one query or do I just have to do 2 queries?

ta.
__________________
"Trouble with the French is they have no word for Entrepreneur"

Quote:
Originally Posted by Xenophon View Post
Ruprect is awarded +5 Xeno Geek Points.
...
*In addition, the following posters are awarded +15 Xeno Geek Points:
Ruprect
Ruprect is offline   Reply With Quote
Old 2nd October 2008, 15:01   #35
Spacecadet
Super poster
 
Spacecadet's Avatar
 
Join Date: Mar 2006
Location: Jupiter
Posts: 3,104
Default

(select distinct <primary key fields> from customer_snapshot where date in (<today>, <tomorrow>) as clist
left outer join
(select * from customer_snapshot where date = <today>) as today
on clist.<pkey fields> = today.<pkey fields>
left outer join
(select * from customer_snapshot where date = <yesterday>) as yesterday
on clist.<pkey fields> = yesterday.<pkey fields>

it will hamper performance though.. there's probably a better way but with only 1 table to look at its difficult to tell

Last edited by Spacecadet : 2nd October 2008 at 15:03.
Spacecadet is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT. The time now is 22:20.


Advertisers
PayStream

CUK Navigation

Contractor Alliance
Formed a new Ltd Co?

20% off business insurance
£10 off Bauer & Cottrell contract reviews
Find co-workers & client introductions

Increase your value to clients here

Fast Company Formation
Same day online company formation £75 + VAT

Form your Ltd Co Here

Contractor Services


 
Content Relevant URLs by vBSEO 2.4.0 © 2005, Crawlability, Inc.