Oracle数据库表起别名不用as,使用as报错

Oracle数据库给表起别名不要 as 关键字, 字段起别名用 as

实战sql 

-- 某个时间段统计该委托企业占比数量 , 先分组查占比百分比,在机关名称左连接机关名称表,在查时间字段左连接表内多条记录时间内最新一条
SELECT
a.*, b.createtime FROM ( SELECT t.*, t1.swjgmc FROM ( SELECT STF_NSRSBH, STF_NSRMC, stf_djxh, stf_zgswskfj_dm, ROUND( SUM( CASE WHEN createtime BETWEEN to_date( '2022-01-01', 'yyyy-MM-dd' ) AND to_date( '2022-06-28', 'yyyy-MM-dd' ) + 1 THEN 1 ELSE 0 END ) / COUNT( * ), 2 ) * 100 || '%' sjzb, SUM( CASE WHEN createtime BETWEEN to_date( '2022-01-01', 'yyyy-MM-dd' ) AND to_date( '2022-06-28', 'yyyy-MM-dd' ) + 1 THEN 1 ELSE 0 END ) AS qjhs, COUNT( * ) AS zhs FROM TB_PLSB_WTSQGL WHERE yxbz = 'Y' AND xqzt = '1' GROUP BY STF_NSRSBH, STF_NSRMC, stf_djxh, stf_zgswskfj_dm ) t LEFT JOIN dm_gy_swjg t1 ON t.stf_zgswskfj_dm = t1.swjg_dm ) a LEFT JOIN ( SELECT DISTINCT b.STF_NSRSBH, MAX( b.createtime ) AS createtime FROM TB_PLSB_WTSQGL b WHERE b.createtime BETWEEN to_date( '2022-01-01', 'yyyy-MM-dd' ) AND to_date( '2022-06-28', 'yyyy-MM-dd' ) + 1 GROUP BY b.STF_NSRSBH ) b ON a.STF_NSRSBH = b.STF_NSRSBH;

 

posted @ 2022-07-01 14:30  漫步花海下的oldman  阅读(621)  评论(0编辑  收藏  举报