dongqingchan2385 2017-06-10 09:05
浏览 15
已采纳

如何找到新客户?

I ran into one problem that I can not solve for 3 days already. The problem is current, there is a database of two columns of date ("yyyy-mm") and the phone number is unique non-repeating. I want to find out how many new customers each month. Well, the formula is roughly current (the new client is the first month + the new client is the next month ....). If the customer meets the first month he is considered a new customer, then it is on the other month, he is missing a new customer.

  • 写回答

2条回答 默认 最新

  • duanmie9682 2017-06-10 09:38
    关注

    try Something like this:

    select year(f2.DateColumn) YearCol,  month(f2.DateColumn) MonthCol, count(f2.PhoneNumber) NbNewPhone
    from (
            Select f1.*,  row_number() over(partition by f1.PhoneNumber order by f1.DateColumn) rang
            from yourTable f1
    ) f2 
    where f2.rang=1
    group by year(f2.DateColumn),  month(f2.DateColumn)
    order by 1, 2
    

    or if you column is not a date :

    select f2.DateColumn, count(f2.PhoneNumber) NbNewPhone
    from (
            Select f1.*,  row_number() over(partition by f1.PhoneNumber order by f1.DateColumn) rang
            from yourTable f1
    ) f2 
    where f2.rang=1
    group by f2.DateColumn
    order by 1, 2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题