sql还是很菜的菜鸟 2021-05-21 03:39 采纳率: 50%
浏览 151
已采纳

sql中应该如何实现表中两列数据相除?

WITH nl_sentcount
AS(
       Select nl_id, count(distinct user_id) as sent_num from sheet1$ Where event_type='nlsent' group by nl_id
)
, nl_opencount AS (
  SELECT nl_id, count(distinct user_id) as open_num from Sheet1$ where event_type = 'nlpv' group by nl_id
)
select a.nl_id, sent_num, open_num
from nl_sentcount a
inner join nl_opencount b
on a.nl_id = b.nl_id

目前我有上述一段代码,然后结果是这样的

我想问一下如果我想在这个表里在加一列open rate (open_num/sent_num) ,应该怎么修改代码?

  • 写回答

3条回答 默认 最新

  • benbenli 2021-05-21 05:17
    关注
    WITH nl_sentcount
    AS(
           Select nl_id, count(distinct user_id) as sent_num from sheet1$ Where event_type='nlsent' group by nl_id
    )
    , nl_opencount AS (
      SELECT nl_id, count(distinct user_id) as open_num from Sheet1$ where event_type = 'nlpv' group by nl_id
    )
    select a.nl_id, sent_num, open_num,
            open_num / sent_num as open_rate
    from nl_sentcount a
    inner join nl_opencount b
    on a.nl_id = b.nl_id
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)
  • ¥50 Qt在release捕获异常并跟踪堆栈(有Demo,跑一下环境再回答)
  • ¥30 python,LLM 文本提炼
  • ¥15 关于将inet引入的相关问题
  • ¥15 关于一个倒计时的操作和显示设计
  • ¥15 提问STK的问题,哪位航天领域的同学会啊
  • ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 如何卸载arcgis 10.1 data reviewer for desktop