先看一张表

MySQL查询order by相减select相减的Sql语句-LMLPHP

create_time是订单创建时间,pay_time是支付时间

现在我想按照订单完成耗时的时间进行排序,并且取出来的数据中直接算好了差值,怎么用Sql呢,请看

select id,tid,payment_type,create_time,pay_time,(UNIX_TIMESTAMP(pay_time)-UNIX_TIMESTAMP(create_time))timeout from upay_order where pay_status=1 and create_time>'2016-04-15' and (UNIX_TIMESTAMP(pay_time)-UNIX_TIMESTAMP(create_time))>60 order by (UNIX_TIMESTAMP(pay_time)-UNIX_TIMESTAMP(create_time)) desc;

MySQL查询order by相减select相减的Sql语句-LMLPHP

04-27 00:13