當(dāng)前位置:首頁(yè) > IT技術(shù) > 數(shù)據(jù)庫(kù) > 正文

MySQL兩個(gè)表聯(lián)合查詢并按時(shí)間排序
2021-10-11 15:05:41

有一張資金記錄表,一張金幣記錄表,想以時(shí)間為單位,降序合并排列他們之間的信息,查詢SQL如下:

select * from (select * from t_money_logs union select * from t_gold_logs) as c order by create_time desc;


select * from (select 
o.ORDER_NUM as order_sn,
o.GOODS_NAME as GOODS_NAME,
o.CREATE_TIME as CREATE_TIME,
"goods" as type
from ayy_order o union select

s.ORDER_NUM as order_sn,
s.GOODS_NAME as GOODS_NAME,
s.CREATE_TIME as CREATE_TIME,
"service" as type
from ayy_service_order s) as c order by CREATE_TIME desc;

本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >