当前位置:Gxlcms > mysql > sql多表连接查询

sql多表连接查询

时间:2021-07-01 10:21:17 帮助过:18人阅读

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

人气教程排行