簡體   English   中英

如何從mysql中同一個表中的最大日期獲取最大時間

[英]how to get max time from max date in the same table in mysql

select sync_date, max(sync_end_time),user_code from sync_tracker where 
sync_action = 'COMPLETION' 
and sync_status = 'SUCCESS'
and user_code in (select ut.code from user_table ut
   join user_location_mapping ulm
   on ut.code = ulm.user_code) 
and sync_date = MAX(sync_date)-- can't even write aggregate function
group by sync_date,user_code
order by sync_date desc

User_code recent_login_date recent_login_time
0012      2016_11_11        11:30:23
0013      2016_1_19         12:30:23
0014      2016_12_4         1:30:23

我想要最近的日期和時間,其中那些是不同的列。 請幫我找出同樣的問題,它給出了我應該使用“EXISTS”作為 sbquery 返回多個記錄的錯誤。

    select st.user_code, tAux.dateMax, max(st.sync_end_time) as timeMax
    from sync_tracker st
    inner join 
    (
    select user_code, max(sync_date) as dateMax
    from sync_tracker 
    inner join user_table ut on user_code = ut.code
    inner join user_location_mapping ulm on ut.code = ulm.user_code
    where sync_action = 'COMPLETION' 
    and sync_status = 'SUCCESS'
    group by user_code, sync_date
    ) tAux
    on st.user_code = tAux.user_code and st.sync_date = tAux.dateMax
    group by st.user_code, tAux.dateMax
    order by dateMax, timeMax

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM