Sql server 假錶左連線

2021-04-29 22:02:52 字數 2024 閱讀 5579

1.

select k1,name1,k2,name2 from(select '2'as k1, 'fan' as name1) as a

left join

(select k2,name2 from(select '2'as k2, 'hui' as name2) as b) as c

on a.k1 = c.k2

2.select m.title, week1,w1,w2 from(

select * from(

select

'前年販売數' as title,

'' as week1,

'' as week2,

'' as week3,

'' as week4,

'' as week5,

'' as week6,

'' as week7,

'' as week8,

'' as week9,

'' as week10,

'' as week11,

'' as week12,

'' as week13,

'' as week14,

'' as week15,

'' as week16,

'' as week17,

'' as week18,

'' as week19,

'' as week20,

'' as week21,

'' as week22,

'' as week23,

'' as week24,

'' as week25,

'' as week26,

'' as week27,

'' as week28,

'' as week29,

'' as week30,

'' as t1,

'' as t2,

'' as t3,

'' as t4,

'' as t5

) as t1

union all

select * from(

select

'當年販売數' as title,

'' as week1,

'' as week2,

'' as week3,

'' as week4,

'' as week5,

'' as week6,

'' as week7,

'' as week8,

'' as week9,

'' as week10,

'' as week11,

'' as week12,

'' as week13,

'' as week14,

'' as week15,

'' as week16,

'' as week17,

'' as week18,

'' as week19,

'' as week20,

'' as week21,

'' as week22,

'' as week23,

'' as week24,

'' as week25,

'' as week26,

'' as week27,

'' as week28,

'' as week29,

'' as week30,

'' as t1,

'' as t2,

'' as t3,

'' as t4,

'' as t5

) as t2

) as m

left join

(select title,w1,w2 from(

select

'前年販売數' as title,

'1' as w1,

'2' as w2

) as n

) as n1

on m.title = n1.title

SQLSERVER各種表連線

2.1常用表連線 inner join,left join,right join,full join,cross join if object id n table1 n u is not null drop table table1 if object id n table2 n u is not...

左連線 左外連線 右外連線

在之前,我對mssql中的內連線和外連線所得出的資料集不是很清楚。這幾天重新溫習了一下sql的書本,現在的思路應該是很清楚了,現在把自己的理解發出來給大家溫習下。希望和我一樣對sql的連線語句不太理解的朋友能夠有所幫助。發這麼菜的教程,各位大大們別笑話偶了,呵 d 有兩個表a和表b。表a結構如下 a...

SQL左外連線連線多個表

標籤 sql join 資料庫測試 2007 03 25 02 50 10637人閱讀收藏 舉報 遇到問題說是要多個表生成乙個view,那麼應該用到連線,查了乙個關於多個表連線的方法.如下 create view vitem as item.id,cargo.id,charge.id,custome...