当前位置: 首页 > 图文教程 > 数据库 > MSSQL > sql 多表连接查询

MSSQL
SQL Server 数据库操作实用技巧锦集
SQL Server转换为XQuery及反向转换
SQL Server 数据库崩溃后的恢复之法
在 SQL Server数据库开发中的十大问题
SQL Server 2000日志转移实现高可用性
帮你六步改善SQL Server安全规划全攻略
教你如何在SQL Server计算机列和平均值
理解 SQL Server 中系统表Sysobjects
用实例分析如何整理SQL Server输入数据
让VB实现SQL Server 2000存储过程调用
利用OBJECT_DEFINITION函数来代码存档
DTS构建组件及其如何完成数据转换服务
编写SQL Server的扩展存储过程实例
SQL Server和Oracle并行处理方法对比
SQL Server数据转换服务基本概念介绍
如何由Sybase向SQL Server移植数据库
如何在SQL Server中由原子建立分子查询
SQL Server用触发器强制执行业务规则
SQL Server数据库导入MySQL数据库体验
SQL Server可写脚本和编程扩展SSIS包

MSSQL 中的 sql 多表连接查询


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 129 ::
收藏到网摘: n/a

sql 多表连接查询语句代码,大家可以参考下。 select * from (SELECT id,jihao, ht.hetongid, hetonghao, banshichu, zulindanwei, jiansheluduan, shebeijinchangriqi,hetongfangshi,
jine,yusuangongchengliang,(ht.jine/30)*(datediff(day,ht.shebeijinchangriqi,getdate())) as yusuanjine,yihuikuanjine,
((ht.jine/30)*(datediff(day,ht.shebeijinchangriqi,getdate()))-yihuikuanjine) as qiankuanjine,ht.shebeituichangriqi
FROM db_hetongguanli_y_g as ht left join select sum (gongchengliang) as yusuangongchengliang ,hetongid
from db_meirigongchengliang group by hetongid) as d on ht.hetongid=d.hetongid left
join(select sum(shijihuikuanjine) as yihuikuanjine,hetongid from db_huikuan group by hetongid) as a on ht.hetongid=a.hetongid ) as b
where b.hetongfangshi='月租' and b.hetongid=(select hetongid from db_shebeixinxi where jihao='" + this.DropDownList1.SelectedValue + "')";
==================================================================================================
select * from (select ht.id,ht.qiandingren,ht.hetongid,ht.banshichu,ht.jihao,ht.hetonghao,ht.zulindanwei,
ht.jiansheluduan,ht.qingqianriqi,ht.lumianshigongcailiao,ht.hetongfangshi,ht.jine,ht.hetongqiandingriqi,
ht.hetongjiesuanjine,ht.hetongjiesuanriqi,ht.shebeijinchangriqi,ht.shebeituichangriqi,ht.jiesuangongchengliang,
d.yifukuanjine, (ht.hetongjiesuanjine-d.yifukuanjine) as qiankuanjine,ht.kaipiaojine,ht.ranyoufei,ht.yunfei,
ht.qitafeiyong,ht.feiliaofei from db_hetongguanli_y_g as ht left join (select hetongid,sum(shijihuikuanjine) as yifukuanjine
from db_huikuan group by hetongid) as d on ht.hetongid=d.hetongid) as a
where a.hetongid=(select hetongid from db_shebeixinxi where jihao='5666')
go