だから、それぞれuser_id
にoperation_timestamp
というテーブルがあります。私は結果を取得しましょう、私は小数に変換し、クエリmax(operation_timestamp)-min(operation_timestamp)
を使用し、各user_id
のためにかかった時間、アクションを確認するには:各user_idの合計時間
SHIFT USER ID MIN MAX MAX-MIN DECIMAL
shift1 user_1 08:19:42 09:55:20 01:35:37 1.59
shift2 user_2 10:04:27 10:28:22 00:23:54 0.40
shift2 user_3 10:44:07 10:55:58 00:01:51 0.04
shift2 user_4 06:25:33 10:51:52 04:26:19 4.44
今、私の質問:私は小数で時間の合計をうまくする方法すべてのユーザーのアクティビティに費やす時間はどれくらいですか?このような何か:私はそれは、その後、別のuser_idを見ずに、最大と最小を計算しているが、group by user_id
機能なしで同じクエリを試してみましたので、それが結果を与えるだろう06:25:33 (user_4) to 10:55:58 (user_3)
としてshift2
合計を計算します言わせている
SHIFT TOTAL_DECIMAL
shift1 1.59
shift2 4.88
小数点では4.45
です。
これは私が成功せずに使用したクエリです:
select
case
when SUBSTR(a.operation_ts,12,13) between '00:00:00.000' and '05:59:59.000' then 'Nights'
when SUBSTR(a.operation_ts,12,13) between '06:00:00.000' and '13:59:59.000' then 'Days'
when SUBSTR(a.operation_ts,12,13) between '14:00:00.000' and '21:59:59.000' then 'Lates'
when SUBSTR(a.operation_ts,12,13) between '22:00:00.000' and '23:59:59.000' then 'Nights'
else 'other'
end as shift,
a.userid,
substr(min(a.operation_ts),11,9),
substr(max(a.operation_ts),11,9),
substr((max(a.operation_ts)-min(a.operation_ts)),10,9) as time_on_go,
round(((substr((max(a.operation_ts)-min(a.operation_ts)),11,2))*3600+(substr((max(a.operation_ts)-min(a.operation_ts)),14,2))*60+(substr((max(a.operation_ts)-min(a.operation_ts)),17,2)))/3600,2) time_decimal
from dc_sys_common:user_operation a
where a.activity_code = 1012
and date(a.operation_ts) between today and today+1
and SUBSTR(a.operation_ts,12,9) between '00:00:00' and '21:59:59'
group by userid, shift
having max(a.operation_ts)-min(a.operation_ts)>'0 00:00:01.000'
order by shift asc
試しましたが、エラーが発生します: '集約内に集約はありません。 ' – user7557185
これはうまくいくはずです。質問を編集し、実際のクエリを追加してください。 –