标题: 业务表构建中一些特殊字符作为列名的构建示例 [打印本页] 作者: 王爱东 时间: 2020-6-15 10:26 标题: 业务表构建中一些特殊字符作为列名的构建示例 度量快速开发平台中,业务表构建的时候,可能会有设置列的名称为数字开头的,正常情况下数据库的列明不能是以数字开头的,比如:
select a.SUOSHUDANWEIID,sum(case when b.JIANCHAXIANGMU = 'GPS未在线' then 1 else 0 end) GPS未在线,
SUM(case when b.JIANCHAXIANGMU = '3G视频不合格' then 1 else 0 end) 3G视频不合格
from PROJECT_CHECK a,PROJECT_CHECK_DETAIL b
where a.ID = b.LIBAOLIJIANID and b.SHIFOUHEGE = 0 group by SUOSHUDANWEIID
一般情况下,我们在查询分析器中,就会在有数字的列明上加上中括号或者 是双引号。
方法一:
select a.SUOSHUDANWEIID,sum(case when b.JIANCHAXIANGMU = 'GPS未在线' then 1 else 0 end) GPS未在线,
SUM(case when b.JIANCHAXIANGMU = '3G视频不合格' then 1 else 0 end) [3G视频不合格]
from PROJECT_CHECK a,PROJECT_CHECK_DETAIL b
where a.ID = b.LIBAOLIJIANID and b.SHIFOUHEGE = 0 group by SUOSHUDANWEIID
方法二:
select a.SUOSHUDANWEIID,sum(case when b.JIANCHAXIANGMU = 'GPS未在线' then 1 else 0 end) GPS未在线,
SUM(case when b.JIANCHAXIANGMU = '3G视频不合格' then 1 else 0 end) as "3G视频不合格"
from PROJECT_CHECK a,PROJECT_CHECK_DETAIL b
where a.ID = b.LIBAOLIJIANID and b.SHIFOUHEGE = 0 group by SUOSHUDANWEIID