zoukankan      html  css  js  c++  java
  • LC1127. 用户购买平台

    题目链接

     

     

    题解:

    这道题太复杂了。。。主要是前两列最开始比较难想怎么做。

    # Write your MySQL query statement below
    
    select t4.spend_date, t4.platform, if(t6.spend_date is null,0,t6.amount) as total_amount,
            if(t6.spend_date is null, 0, users) as total_users 
    from
    (
        select spend_date, platform, t3.prk from 
        (select distinct spend_date from Spending) t1
        join 
        (
            select * from(
            select 'desktop' as platform, '1' as prk 
            union all 
            select 'mobile' as platform, '2' as prk 
            union all
            select 'both' as platform, '3' as prk 
            )t2
        )t3
    )t4     
    left join 
    (
        select spend_date, platform, sum(amount) as amount, count(user_id) as users from
        (
        select spend_date, user_id,
            (
                case when count(platform)>1 then 'both' 
                else platform 
                end 
            )as platform,
            sum(amount) as amount 
        from Spending group by spend_date,user_id  
        )t5     # spend_date, user_id
        group by spend_date, platform 
    )t6    # spend_date, platform
    on t4.spend_date=t6.spend_date and t4.platform=t6.platform
    order by t4.spend_date, t4.prk
  • 相关阅读:
    NOIP1998提高组——挖地雷
    模板——EXBSGS
    vue 知识点
    jq_js
    ruby 基础知识(一)
    idea maven pom配置文件
    .net core dapper (5)
    .net core dapper (4)
    .net core dapper (3)
    .net core dapper (2)
  • 原文地址:https://www.cnblogs.com/FEIIEF/p/12270136.html
Copyright © 2011-2022 走看看