我有一个表call,其中有两列Customer_Phone_Number和DateTime。
我在这里想做的是,对昨天 18:00-10:00PM 之间给我打电话的客户在过去 14 天内重复计数
示例文件 - Sample_Excel_File
请帮忙
最佳答案
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;
关于MySql 根据多个条件提供重复计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38395723/