程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 使用派生表

使用派生表

編輯:關於SqlServer


1.此示例使用派生表和緊跟 FROM 子句的 SELECT 語句,返回所有作者的姓名以及所著書的標題的書號。

USE pubs
SELECT RTRIM(a.au_fname) + '''' '''' + LTRIM(a.au_lname) AS Name, d1.title_id
FROM authors a, (SELECT title_id, au_id FROM titleauthor) AS d1
WHERE a.au_id = d1.au_id
ORDER BY a.au_lname, a.au_fname
2。相當於 case的
select distinct (ww.dates),(select price from adt1 b where id=1 and ww.dates=b.dates)as w1,(select price from adt1 c where id=2 and ww.dates=c.dates)as w2,(select price from adt1 d where id=3 and ww.dates=d.dates)as w3
from adt1 ww
order by ww.dates
3。select a.dates,a.price as w1,b.price as w2,c.price as w3
from (select * from tablename where id=1)as a,
(select * from tablename where id=2 )as b,
(select * from tablename where id=3) as c
where a.dates=b.dates and b.dates=c.dates
order by a.dates

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved