热门文章
 
Transact_SQL索引
应用程序中的高级SQL注入
sql server数据转换
子查询
使用约束
case 的用法
生成测试数据 T-SQL系列
经典查询排序案例
获取排队顺序 T-SQL教案
查找不同时间段间的差异 T-
 推荐文章
 
join 方式
SQL Server中保存和
SELECT TOP N 问
SQL Server中的全文
sql server 由于登
SQL Server2005
怎样将Varbinary数据
MS SQL SERVER
数据分组
distinct id的取法
SQL Server安全防范
MD5算法的T-SQL实现
改变自增字段的初始值
sql server 数据恢
使用派生表
几个SQL日志有关的概念
 
你现在的位置:您现在的位置是: 中国ASP>>数据库>>sql server
使用派生表

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

相关信息:

.Net下调用SqlServer2k存储过程
SQLServer分页查询通用存储过程
access升级到SQLServer如何调整字段类型及函数:JET SQL 和T-SQL中的同义词
Transact_SQL索引
应用程序中的高级SQL注入
sql server数据转换
子查询
使用约束
case 的用法

 

中国ASP技术 ASP.ORG.CN 版权所有 2004-2008