select '#{time yyyyMMdd}0000' TIME_ID, a.IMSI, a.GJ, a.YYS, count(case when substr(b.IMSI,1,5)<>46000 and b.operate_code=2 then a.IMSI else null end) as MRWZGXQQCS, count(case when substr(b.IMSI,1,5)<>46000 and b.operate_code=2 and b.result<>1 then a.IMSI else null end) as MRWZGXCGCS, case when count(case when substr(b.IMSI,1,5)<>46000 and b.operate_code=2 then a.IMSI else null end)=0 then 0 else count(case when substr(b.IMSI,1,5)<>46000 and b.operate_code=2 and b.result<>1 then a.IMSI else null)/count(case when substr(b.IMSI,1,5)<>46000 and b.operate_code=2 then a.IMSI else null end) as MRWZGXCGL, sum(c.MRZJCS) as MRZJCS, sum(c.MRZJHJCGCS) as MRZJHJCGCS, sum(d.MRBJCS) as MRBJCS, sum(d.MRBJHJCGCS) as MRBJHJCGCS, case when sum(c.MRZJCS)=0 then 0 else sum(c.MRZJHJCGCS)/sum(c.MRZJCS) end as MRZJWLJTL, case when sum(c.MRZJCS)=0 then 0 else sum(d.MRBJHJCGCS)/sum(d.MRBJCS) end as MRBJWLJTL, count(case when substr(b.msc,1,2)<>86 and a.GJ is not null and b.operate_code=2 then a.IMSI else null end) as MCWZGXQQCS, count(case when substr(b.msc,1,2)<>86 and a.GJ is not null and b.operate_code=2 and b.result<>1 then a.IMSI else null end) as MCWZGXCGCS, case when count(case when substr(b.msc,1,2)<>86 and a.GJ is not null and b.operate_code=2 then a.IMSI else null end)=0 then 0 else count(case when substr(b.msc,1,2)<>86 and a.GJ is not null and b.operate_code=2 and b.result<>1 then a.IMSI else null end)/ count(case when substr(b.msc,1,2)<>86 and a.GJ is not null and b.operate_code=2 then a.IMSI else null end) as MCWZGXCGL, now() LOAD_TIME from (select * from TAB_A union select * from TAB_B union select * from TAB_C)a left join (select * from spark_odc_dwd.D_ENS_GMAP_MM where p_hour='#{time yyyyMMddHH}') b on a.IMSI=b.IMSI left join TAB_D c on a.IMSI=c.calling_imsi left join TAB_E d on a.IMSI=d.called_imsi group by a.IMSI, a.GJ, a.YYS
时间: 2024-04-26 21:24:38 浏览: 87
这段 SQL 查询语句看起来是对多个数据表进行联合查询,并进行一些聚合操作,得出一些业务指标。其中包括了一些计数、求和和分组等操作,主要目的是对不同条件下的数据进行统计和分析,以便于业务决策。需要注意的是,这里的 SQL 查询语句中含有一些参数,如 `#{time yyyyMMdd}` 和 `#{time yyyyMMddHH}`,需要在使用时进行替换。同时,这段代码中所用到的数据表和字段名称也需要根据实际场景进行调整。
相关问题
select a.dt,count(b.account_id)/count(a.account_id) from ( select distinct account_id from src_loginrole_day where dt <=20180606 and dt>= 20180604 )a left JOIN ( select distinct account_id from src_loginrole_day where dt <=20180607 and dt>= 20180605 )b on a.account_id = b.account_id and datediff(from_unixtime(unix_timestamp(b.dt,'yyyyMMdd')),from_unixtime(unix_timestamp(a.dt,'yyyyMMdd'))) = 1 group by a.dt;哪里有错
这个 SQL 查询语句中存在语法错误。经过查看,发现在子查询中的 `src_loginrole_day` 表缺少别名。
以下是修正后的 SQL 查询语句:
```
SELECT a.dt, COUNT(b.account_id) / COUNT(a.account_id)
FROM (
SELECT DISTINCT account_id, dt
FROM src_loginrole_day
WHERE dt <= 20180606 AND dt >= 20180604
) a
LEFT JOIN (
SELECT DISTINCT account_id, dt
FROM src_loginrole_day
WHERE dt <= 20180607 AND dt >= 20180605
) b ON a.account_id = b.account_id AND DATEDIFF(FROM_UNIXTIME(UNIX_TIMESTAMP(b.dt,'yyyyMMdd')),FROM_UNIXTIME(UNIX_TIMESTAMP(a.dt,'yyyyMMdd'))) = 1
GROUP BY a.dt;
```
在这个修正后的查询语句中,我为子查询中的 `src_loginrole_day` 表添加了别名 `a` 和 `b`,并且在 SELECT 子句中添加了 `dt` 字段,以便在后面的 JOIN 操作中使用。
select a.dt,count(distinct b.account_id)/count(distinct a.account_id)as rate from ( select account_id,dt from src_logoutrole_day where dt between 20180604 and 20180606 )a left join ( select account_id,dt from src_logoutrole_day where dt between 20180605 and 20180607 )b on a.account_id = b.account_id and datediff(from_unixtime(unix_timestamp(b.dt,'yyyyMMdd')),from_unixtime(unix_timestamp(a.dt,'yyyyMMdd'))) = 1 group by a.dt order by a.dt;有错吗
这个 SQL 语句看起来没有语法错误,但是可能存在逻辑或数据问题。这个 SQL 语句是为了计算在一段时间内,前一天和后一天都有登录的玩家占总登录玩家数的比例。需要确认以下几点:
1. 数据表 src_logoutrole_day 中是否包含 account_id 和 dt 两个字段。
2. 时间范围是否正确,确保时间范围内有数据。
3. 是否存在同一天内多次登录的玩家,如果存在,需要去重。
4. 是否存在某个日期的登录数据没有被匹配到对应的前一天或后一天数据,这种情况下会导致计算不准确。
如果以上问题都排除了,那么可以执行该 SQL 语句并检查输出结果来验证逻辑是否正确。
阅读全文