现在的位置: 首页 > 综合 > 正文

SQL order by 用法

2016年07月14日 ⁄ 综合 ⁄ 共 532字 ⁄ 字号 评论关闭
文章目录

      这是查询时候需要按照某些规则排序查询的结果,用order by

    自创公式:select 字段 from 表 where 条件 order by 字段

    例子(Oracle数据库)MySQL一样的如下:

select  td.m_mailcode,id, packageno, setpost, arrivepost, flight, bagno, mailno, weight, sealingdate,
  (case sealingtype when '1' then '航挂' when '2' then '平邮'else '未知'end) as sealingtype, orderno, createtime, oper_user, oper,
  (case mailtype when '1' then '正常件' when '2' then '退件' else '未知' end) as mailtype   from ipcs_tb_waybilltest t,ipcs_tb_waybilldetail td
  where t.id=td.w_id(+) and t.sealingdate='2014-10-21' order by t.mailtype asc,t.sealingtype asc,t.id asc

   用此语句纪念下最近用的case when 和order by

抱歉!评论已关闭.