首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于一个sql利率的异常

2012-10-15 
关于一个sql利率的错误select cast(count(*)as decimal) from tb_jbkhb group by datepart(year,tb_jbkhb.

关于一个sql利率的错误
select cast(count(*)as decimal) from tb_jbkhb group by datepart(year,tb_jbkhb.gcsj),datepart(month,tb_jbkhb.gcsj)/select cast(count(*)as decimal) from tb_yxgzb group by datepart(year,tb_yxgzb.sjjdsj),datepart(month,tb_yxgzb.sjjdsj)

按照年份和月份分组算出利率 两个查询单独都能查出东西 组合一起 就一直报错“消息 156,级别 15,状态 1,第 1 行
关键字 'select' 附近有语法错误。”

[解决办法]
上面表名给弄错了

SQL code
select a.iYear, a.iMonth, a.num/case b.num when 0 then null else b.num from( select cast(count(*)as decimal)num ,datepart(year,tb_jbkhb.gcsj) iYear ,datepart(month,tb_jbkhb.gcsj) iMonth from tb_jbkhb group by datepart(year,tb_jbkhb.gcsj),datepart(month,tb_jbkhb.gcsj)) a inner join(select cast(count(*)as decimal)num,datepart(year,tb_yxgzb.gcsj) iYear ,datepart(month,tb_yxgzb.gcsj)iMonth  from tb_yxgzb group by datepart(year,tb_yxgzb.sjjdsj),datepart(month,tb_yxgzb.sjjdsj)) b on a.iYear=b.iYear and a.iMonth=b.iMonth 

热点排行
Bad Request.