»

with句再考(≒最高)

SQL Server — タグ: , — enjoji.yasujiro @ 12:01 AM

■最近自分も学習したのだけど、with句には複数設定することが可能らしい↓

with t1 as( /*@SQL鯖2005 */
select rowid= 1,isbn = 4492042997 union all
select rowid= 2,isbn = 4774135380
),t2 as(
select isbn = 4492042997,bknm = ‘出逢いの大学’,authorid= ‘p1′ union all
select isbn = 4774135380,bknm = ‘小さなニュースに火をつけて売る!’,authorid=’p2′
),t3 as(
select authorid=’p1′,authorname = ‘千葉智之’ union all
select authorid=’p2′,authorname = ‘松本拓也’
)

select rowid
, bookname = bknm
, isbncode = x.isbn
, author = authorname
from t1 x
left outer join t2 y
on x.isbn = y.isbn
left outer join t3 z
on y.authorid = z.authorid

※select文の結果↓

(続きを読む…)

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2009 鎌倉橋日記 | powered by WordPress with Barecity