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

MSSQL
Microsoft SQLServer的版本区别及选择
在SQL Server数据库中为标识(IDENTITY)列插入显式值
访问和更改关系数据,使用MSSQL外联接
一个查看MSSQLServer数据库空间使用情况的存储过程 SpaceUsed
SQL语句去掉重复记录,获取重复记录
复习一下sql server的差异备份
SQL中object_id函数的用法
SQL Server日期计算
找回SQL企业管理器里的SQL连接的密码的方法
mssql数据库系统崩溃后的一般处理步骤与方法
海量数据库的查询优化及分页算法方案
SQL Server连接中三个常见的错误分析
在程序中压缩sql server2000的数据库备份文件的代码
MS SQL SERVER 数据库日志压缩方法与代码
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
将Session值储存于SQL Server中

MSSQL 中的 sql 多表连接查询


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 37 ::
收藏到网摘: 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