SQL问题

改名后的栏名指定不了为啥呢?

select count(*),保険料_前:: int - 保険料_後:: int as 更改増減 from carapproachgetdata('${p_kashisha}','${p_dairiten}','${p_dairiten_pattern}','${p_tengai}','${p_koukai}','${p_year_1}','${p_s_month}','${p_year_2}','${p_e_month}') where 保険料_後 != ' ' and  更改増減<0


在where后面加 

保険料_後 != ‘’  and  更改増減<0

不好用

说没有、更改増減

as 改完后用不了吗?应该咋办呢?

minamoto 发布于 2020-12-8 17:09 (编辑于 2020-12-8 17:13)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
axingLv6专家互助
发布于2020-12-8 17:18

sql的执行顺序是先where再select的,所以在select后面取的别名不能在where中使用

正确应该为

select count(*),保険料_前:: int - 保険料_後:: int as 更改増減 from carapproachgetdata('${p_kashisha}','${p_dairiten}','${p_dairiten_pattern}','${p_tengai}','${p_koukai}','${p_year_1}','${p_s_month}','${p_year_2}','${p_e_month}') where 保険料_後 != ' ' and  保険料_前:: int - 保険料_後:: int<0

select * from (
select count(*),保険料_前:: int - 保険料_後:: int as 更改増減 from carapproachgetdata('${p_kashisha}','${p_dairiten}','${p_dairiten_pattern}','${p_tengai}','${p_koukai}','${p_year_1}','${p_s_month}','${p_year_2}','${p_e_month}') 
) as t
where 保険料_後 != ' ' and  保険料_前:: int - 保険料_後:: int<0


  • 2关注人数
  • 233浏览人数
  • 最后回答于:2020-12-8 17:18
    请选择关闭问题的原因
    确定 取消
    返回顶部