mysql - Distinct outside group in sql -


i have table called order_status_log, logs changed order statuses.

simplified table , query below:

order_id     user_id    status    time 1            1          1         2016-01-27 19:35:44 2            2          2         2016-01-27 19:36:45 4            3          2         2016-01-27 19:37:43 2            1          5         2016-01-27 19:38:41 

i have sql counts changes each user:

select     count(*) count,     user_id order_status_log status = 1 group user_id order count 

now want improve query count first status changes in order. in other words need unique order_id older time. how can change query that?

something this?

select * order_status_log o not exists ( select 'x'                    order_status_log o2                    o2.user_id = o.user_id                    , o2.time < o.time                   ) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -