0
我的'call_logs'表具有字段:id,phone_number,call_dialed_time,is_success。 (如果对电话号码的呼叫失败,则我们输入记录并稍后尝试再次呼叫)通过GROUP,HAVING,recency等查询SQL
对于尚未成功拨打的每个电话号码,我想获取最近的phone_number和call_dialed_time失败。
如何查询?
我的'call_logs'表具有字段:id,phone_number,call_dialed_time,is_success。 (如果对电话号码的呼叫失败,则我们输入记录并稍后尝试再次呼叫)通过GROUP,HAVING,recency等查询SQL
对于尚未成功拨打的每个电话号码,我想获取最近的phone_number和call_dialed_time失败。
如何查询?
试试这个。
select distinct phone_number ,call_dialed_time from call_logs where phone_number not in(
select phone_number from call_logs group by phone_number having count(is_success) >0
) order by call_dialed_time
试试这个
select t1.* from call_logs as t1 inner join
(
select
phone_number, max(call_dialed_time) as call_dialed_time from call_logs
where is_success=0
group by phone_number
) as t2 on t1.phone_number=t2.phone_number and t1.call_dialed_time=t2.call_dialed_time
如果一个唯一的编号已成功调用它不检查。如果这个数字有成功的通话,我不想在我的结果中显示。 –
@AayushKarki我更新了查询,试试吧,让我知道你是否需要进一步的帮助。 –