首页 新闻 会员 周边 捐助

Sql怎么写

0
[已解决问题] 解决于 2016-06-04 22:37
SELECT 
(SDMS_OrganiseUnit.OrganiseUnitName), 
COUNT(FMDS_Water_DikeProject.OrganiseUnitName)as shu,
sum(FMDS_Water_DikeProject.NowDikeLength) as NowDikeLength,
(sum(NowAverageIncrease)/COUNT(FMDS_Water_DikeProject.OrganiseUnitName)) as NowAverageIncrease,
(sum(NowCrestWidth)/COUNT(FMDS_Water_DikeProject.OrganiseUnitName)) as NowCrestWidth
 
FROM SDMS_OrganiseUnit 
left join FMDS_Water_DikeProject 
on SDMS_OrganiseUnit.OrganiseUnitID=FMDS_Water_DikeProject.OrganiseUnitID and FMDS_Water_DikeProject.IsDelete=0
 
 
WHERE OrganiseUnitModel=1 AND OrganiseUnitType=3 
AND SDMS_OrganiseUnit.IsDelete=0 
group by SDMS_OrganiseUnit.OrganiseUnitName,DisplayIndex
ORDER BY DisplayIndex 

现在想在查询几列

 

 

就是把和链接表FMDS_Water_DikeProject有关的表FMDS_Water_DikeProject_Buildings查出来,上面写的sql不行,不知道怎么写?

SELECT 
(SDMS_OrganiseUnit.OrganiseUnitName), 
COUNT(FMDS_Water_DikeProject.OrganiseUnitName)as shu,
sum(FMDS_Water_DikeProject.NowDikeLength) as NowDikeLength,
(sum(NowAverageIncrease)/COUNT(FMDS_Water_DikeProject.OrganiseUnitName)) as NowAverageIncrease,
(sum(NowCrestWidth)/COUNT(FMDS_Water_DikeProject.OrganiseUnitName)) as NowCrestWidth,
(select Count(FMDS_Water_DikeProject_Buildings.Name) as Bs from FMDS_Water_DikeProject_Buildings 
left join FMDS_Water_DikeProject
on  FMDS_Water_DikeProject_Buildings.MainID=FMDS_Water_DikeProject.ID 
and FMDS_Water_DikeProject_Buildings.Type=1 group by FMDS_Water_DikeProject_Buildings.Name)
FROM SDMS_OrganiseUnit 
left join FMDS_Water_DikeProject 
on SDMS_OrganiseUnit.OrganiseUnitID=FMDS_Water_DikeProject.OrganiseUnitID and FMDS_Water_DikeProject.IsDelete=0
 
 
WHERE OrganiseUnitModel=1 AND OrganiseUnitType=3 
AND SDMS_OrganiseUnit.IsDelete=0 
group by SDMS_OrganiseUnit.OrganiseUnitName,DisplayIndex
ORDER BY DisplayIndex 
博学多思的主页 博学多思 | 初学一级 | 园豆:76
提问于:2015-10-15 14:44
< >
分享
最佳答案
0

没说清楚,要么说出问题,要么说出想得什么结果!

奖励园豆:5
三瑞 | 菜鸟二级 |园豆:232 | 2015-10-15 14:57

把圈里的sql写出来

博学多思 | 园豆:76 (初学一级) | 2015-10-15 14:59

写到那个位置

博学多思 | 园豆:76 (初学一级) | 2015-10-15 14:59

@博学多思: 圈中的是一个结果集,你这样写肯定会报错,

三瑞 | 园豆:232 (菜鸟二级) | 2015-10-15 15:04

@三瑞: 怎么写?哪的怎么改

博学多思 | 园豆:76 (初学一级) | 2015-10-15 15:24
其他回答(1)
0

把圈里的sql放到from后面用join来连接。

其实圈里的sql 你就可以当一个表来看待

nicky0227 | 园豆:1069 (小虾三级) | 2015-10-16 10:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册