| Author |
Topic |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2003-12-02 : 15:48:57
|
| [code]create table #t (a int, b int)insert into #tselect 1, 20 union allselect 9, 17 union allselect 3, 6 union allselect 33, 44 union allselect 45, 48 union allselect 55, 66 union allselect 59, 62[/code]Result should be:[code]aa bb -------- -------- 1 2033 4445 4855 66[/code]I.e., find left and right boundaries of each union of crossing intervals.. |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2003-12-02 : 15:51:21
|
| Is this homework you're posting?===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2003-12-02 : 16:05:43
|
| No!! I just write a book on SQL and need nice solutions.. :) |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2003-12-02 : 16:41:43
|
| [code]select a,bfrom( select a,b,(select count(*) from #t b where b.a <= a.a and b.b >= a.b) as boundary from #t a) awhere a.boundary = 1[/code] |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2003-12-02 : 17:25:07
|
| Very smart, Jay...... and this is mine:select min(a), bb from(select a, (select max(b) from #t tt where not(tt.a>t.b)) bbfrom #t t) z group by bb |
 |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2003-12-02 : 17:57:22
|
| And in this book you're going to credit all the people that wrote the queries you're publishing right?===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2003-12-02 : 21:12:09
|
| I think Ken Henderson already wrote this bookDamian |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2003-12-02 : 21:29:30
|
quote: What has been is what will be, and what has been done is what will be done; there is nothing new under the sun.
EC 1:9 |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2003-12-03 : 16:32:48
|
| LOL people.. it was a joke - about my book..The maximum of what I'm able to write is 30 lines of forums post.... |
 |
|
|
|