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
没说清楚,要么说出问题,要么说出想得什么结果!
把圈里的sql写出来
写到那个位置
@博学多思: 圈中的是一个结果集,你这样写肯定会报错,
@三瑞: 怎么写?哪的怎么改
把圈里的sql放到from后面用join来连接。
其实圈里的sql 你就可以当一个表来看待