dongwen1871 2015-01-02 10:50
浏览 6

如何在Mysql中进行自定义顺序

Below is my column

1-1
1-2
2-1
2-4

Is It possible to sort in this way - First Column should be be ascending and Second column should be descending

So the result will be

1-4
1-2
2-1
2-1

I don't care if the row mismatch. How can I achieve this (Something like view)

CREATE TABLE IF NOT EXISTS `pipo_orders` (
      `ClientID` int(8) NOT NULL,
      `created_at` datetime NOT NULL,
      `updated_at` timestamp NOT NULL DEFAULT ,
    );

--
-- Dumping data for table `pipo_orders`
--

INSERT INTO `pipo_orders` (`ClientID`, `created_at`, `updated_at`) VALUES
(17, '2014-11-26 16:21:36', '2014-11-26 10:51:36'),
(17, '2014-11-26 16:46:24', '2014-11-26 11:16:24'),
(17, '2014-12-04 16:45:28', '2014-12-04 11:15:28'),
(17, '2014-12-26 12:58:13', '2014-12-26 07:28:13'),
(17, '2014-12-30 14:29:31', '2014-12-30 08:59:31'),
(17, '2014-12-30 14:31:05', '2014-12-30 09:01:05'),
(17, '2015-01-02 12:20:54', '2015-01-02 06:50:54');
  • 写回答

2条回答 默认 最新

  • douzao9845 2015-01-02 11:04
    关注

    If this is what you want it's weird, and I can't think of a reason why you'd want it. In fact, it goes against the fundamental logic of a database... Nevertheless:

    SELECT       t1.ClientID
    ,            t1.created_at
    ,            t2.updated_at
    FROM         pipo_orders t1
    JOIN         pipo_orders t2
           ON    1 = 1
    ORDER BY     t1.created_at ASC
    ,            t2.update_at DESC
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题