求助帖 求大神指点
select sum(nc),sum(bq),sum(qm)
(
select sum(jige) as nc,0 as bq,0 as qm from s_zhgl_Office_dn where to_char(Reghumdate,'yyyy') = to_char((getdate()-1),'yyyy')
union all
select 0 as nc,sum(jige) as bq,0 as qm from s_zhgl_Office_dn where to_char(Reghumdate,'yyyy') = to_char((getdate()),'yyyy')
union all
select 0 as nc,0 as bq,sum(jige) as qm from s_zhgl_Office_dn where to_char(Reghumdate,'yyyy') = to_char((getdate()+1),'yyyy')
)
from s_zhgl_Office_dn
如上 第一次写这种格式的 结果报错了 错误:未找到from要求的关键字 求大神指点
[解决办法]
select sum(nc),sum(bq),sum(qm)
--注释部分应写到from 后面 作为一个‘表’存在的。
--(
--select sum(jige) as nc,0 as bq,0 as qm from s_zhgl_Office_dn --where --to_char(Reghumdate,'yyyy') = to_char((getdate()-1),'yyyy')
--union all
--select 0 as nc,sum(jige) as bq,0 as qm from s_zhgl_Office_dn --where --to_char(Reghumdate,'yyyy') = to_char((getdate()),'yyyy')
--union all
select 0 as nc,0 as bq,sum(jige) as qm from s_zhgl_Office_dn --where --to_char(Reghumdate,'yyyy') = to_char((getdate()+1),'yyyy')
--)
from s_zhgl_Office_dn
--语法:
--select 字段 from 表 where 条件