私は毎日午前7時45分から午後5時まで、タスクスケジュールでPHPスクリプトを実行しています。これは素晴らしい機能ですが、最初の実行ではまだレコードが作成されていないため、何も返されません(レコードをCSRエージェントが呼び出すことによって作成されます)。私は、SQLのクエリを選択し、集計し、テーブルに値を挿入し、それらの値からJSONファイルを作成するスクリプトで実行している。この場合も、最初の実行以外はすべて完璧です。select(タスクスケジューラで実行されているsqlスクリプト)に空の戻り値0を挿入する
これに何かを追加できるかどうか尋ねられました。その最初のジョブが何も返されない場合は、すべてに対して0を挿入します。そうすれば、システムでレコード/コールなしで5回実行されても、データは残っていて、CSR画面には何かが表示されます。これを行うにはかなり簡単な方法がありますか?ここで
は、スクリプトのバルクです:
$data = mysqli_query($conn2,
"SELECT
case
when callingpartyno in (select extension from test.test_users)
then callingpartyno
when finallycalledpartyno in (select extension from test.test_users)
then finallycalledpartyno
end as extension
, sum(duration) as total_talk_time_seconds
, round(sum(duration)/60,2) as total_talk_time_minutes
, sum(if(legtype1 = 1,1,0)) as total_outbound
, sum(case when(legtype1 = 1 and duration > 60) then 1 else 0 end) as credit_for_outbound
, sum(if(legtype1 = 2,1,0) and answered = 1) as total_inbound
, sum(if(legtype1 = 2,1,0) and answered = 0) as total_missed
, sum(if(legtype1 = 1, 1, 0)) + -- outbound calls
sum(if(legtype1 = 2, 1, 0)) as total_calls
,round((sum(if(legtype1 = 2,1,0) and answered = 1))/(sum(if(legtype1 = 1, 1, 0)) + -- outbound calls
sum(if(legtype1 = 2, 1, 0))) * 100,2) as percent_answered
, now() as time_of_report
, curdate() as date_of_report
FROM
test.session a
join test.callsummary b
on a.notablecallid = b.notablecallid
where
date(a.ts) >= curdate()
and (
callingpartyno in (select extension from test.test_users
)
or finallycalledpartyno in (select extension from test.test_users
)
)
group by
extension") or die(mysqli_error($conn2));
$stmt = mysqli_prepare($conn2,
"INSERT into test.test_totals
(extension,
total_talk_time_seconds,
total_talk_time_minutes,
total_outbound,
credit_for_outbound,
total_inbound,
missed_calls,
total_calls,
percent_answered,
date_of_report,
time_of_report)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON duplicate key
update
total_talk_time_seconds = values(total_talk_time_seconds),
total_talk_time_minutes = values(total_talk_time_minutes),
total_inbound = values(total_inbound),
total_outbound = values(total_outbound),
credit_for_outbound = values(credit_for_outbound),
missed_calls = values(missed_calls),
total_calls = values(total_calls),
percent_answered = values(percent_answered),
time_of_report = NOW()") or die(mysqli_error($conn2));
申し訳ありませんが、私はそのフィドルを見て理解すると思いますが、どうすれば既存のクエリを正確に変更する必要がありますか? My now()はselect内の多くの変数の1つで、サブクエリでラップするだけですか? –
かなり、私はビットのmroe情報を与えるために質問を編集します(iphoneから答えを書いた、それは私の上にコードをコピーして貼り付けることに適切な痛みです –
ああ、ありがとう!正しく編集する方法がわかりませんでした。 –