Giter Site home page Giter Site logo

access's People

Watchers

 avatar

access's Issues

【sql 】按字段指定值order by

一、Access

使用IIF函数实现。

SELECT 表1.id, 表1.n
FROM 表1
ORDER BY IIF(n='a3',1,IIF(n='a2',2,IIF(n='a1',3,)));

未解决问题:
1.最里层假值大于3时,1的那项会排在最后面(实际应该排序正常才是,目前只能不填或填最小值);
2.未在指定值的会排在前面,如何让它们排在后面(由于1的影响,asc或desc都实现不了)?

二、Mysql

使用case函数实现。

SELECT 表1.id, 表1.n
FROM 表1
ORDER BY 
CASE n 
WHEN 'a2' THEN 1 
WHEN 'a1' THEN 2 
WHEN 'a3' THEN 3 
ELSE 4 END;

实现效果,排序为a2 a1 a3,其他值排在后面.

三、Oracle

使用decode函数或case函数实现。

1、Decode

       Decode(value,if1,then1,if2,then2,if3,then3.......,else6)

2、Case

      select * from person order by case person_key when 4 then 1 when 5 then 2 when 6 then 3 when 7 then 4 end

Oracle没测试,不说什么。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.