sql多表查詢

2022-10-31 11:09:33 字數 691 閱讀 5107

1樓:

select lineid,id,country from domestic

union all

select lineid,id,country from freedom

-- 聯合查詢domestic,freedom表的lineid,id,country all代表不去除重複

--功能:[sql語句] union [sql語句]將兩個語句中選擇的同一列中的不同的值篩選出來

select《表1>.《列名》 ,《表2>《列名》from《表1>outer join《表2> on《表1>.《列》=表2>.《列名》

--功能:實現兩個表的外連線

select domestic.lineid,freedom.lineid from domestic,freedom where domestic.

sames=freedom.sames

select domestic.lineid,freedom.lineid from domestic inner join freedom on freedom.

sames=domestic.sames

--功能:實現兩個表的內連線 把domestic,freedom兩個表用domestic.sames=freedom.

sames關聯起來顯示domestic.lineid,freedom.lineid

關於sql查詢,想從很多表中查詢欄位值

select q.條碼 case when isnull a.a站點,then t else f end 是否經過a站點 case when isnull b.b站點,then t else f end 是否經過b站點 from 條碼錶 q left join a a on a.條碼 q.條碼lef...

sql多表聯合查詢傳入的日期引數對應兩個欄位,怎麼判斷欄位為空則查詢另欄位,反之查詢這個欄位 求

你這看著那麼麻煩,舉個例子,自己套進去好了。select case when 欄位a is null then 欄位b else 欄位a end from 表名 where 連線和版where條件權正常使用。select 抄case when 欄位a is null then 欄位b else 欄位...

sql考勤統計查詢,sql 考勤統計查詢

select name,dept,count 工作天數,sum xbsj sbsj 工作累計時間,count case when k k 1 then 1 end 遲到天數,count case when k k 2 then 1 end 早退內天容數 from table1 join table2...