MySql根据多个条件提供重复计数

时间:2016-07-15 12:06:50

标签: mysql sql

我有一个表调用,它有两列 Customer_Phone_Number &的日期时间

我在这里要做的是,昨天18:00-10:00之间给我打电话的客户在过去14天内重复计算

示例文件 - Sample_Excel_File

请帮忙

1 个答案:

答案 0 :(得分:0)

Select customer_telephone_number, count(Calls.DateTime) As Count_Calls
From Calls
Where customer_telephone_number In 
(
  Select customer_telephone_number
  From Calls
  Where time_to_sec(date_time) 
        Between time_to_sec(CURRENT_DATE() - INTERVAL 1 DAY) + time_to_sec('10:00:00')
            And time_to_sec(CURRENT_DATE() - INTERVAL 1 DAY) + time_to_sec('18:00:00')
) CustPhonedYesterday
And time_to_sec(date_time) 
          Between time_to_sec(CURRENT_DATE() - INTERVAL 14 DAY) + time_to_sec('00:00:00')
              And time_to_sec(CURRENT_DATE() - INTERVAL 1 DAY) + time_to_sec('18:00:00')
Group By Calls.customer_telephone_number;