sql如何使用派生表

时间:2021-04-16

  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

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章