按IN的顺序对SQL查询进行排序(Sort the SQL Query in the order of IN)
我正在写一个查询
SELECT * FROM EMPLOYEES WHERE EMP_ID IN (10,5,3,9,2,8,6)
我希望结果应按以下顺序排列
Emp_id Emp_Name 10 John 5 Joe 3 Tippu 9 Rich 2 Chad 8 Chris 6 Rose
基本上与IN子句的顺序相同。 有可能吗? 请告诉我。
PS:我可以在SQL中执行此操作,也可以在获取结果集后如果我可以使用LINQ或者在前端选项中进行排序也适用于我(我在前端有数组中的Emp ID)
谢谢
I am writing a query
SELECT * FROM EMPLOYEES WHERE EMP_ID IN (10,5,3,9,2,8,6)
I want the result should be in the following order
Emp_id Emp_Name 10 John 5 Joe 3 Tippu 9 Rich 2 Chad 8 Chris 6 Rose
Basically in the same order of IN Clause. Is it possible to do that? Please let me know.
PS: I can either do it in SQL or after I get the resultset if I can use LINQ or something to sort in front end option also will work for me (I have the Emp IDs in array in front end)
Thanks
原文:https://stackoverflow.com/questions/19531774
更新时间:2022-04-30 10:04
最满意答案
假设
id
是一个数字,你可以做products.sort(({id: previousID}, {id: currentID}) => previousID - currentID)
像这样:
JavaScript代码:
{products .sort(({ id: previousID }, { id: currentID }) => previoudID - currentID) .map(({ id, headline }) => ( <Container> <Row key={id}> <Col> <p>id={id}</p> <p>headline={headline}</p> </Col> </Row> </Container> )) }
Assuming
id
is a number you can doproducts.sort(({id: previousID}, {id: currentID}) => previousID - currentID)
Like so:
JavaScript Code:
{products .sort(({ id: previousID }, { id: currentID }) => previoudID - currentID) .map(({ id, headline }) => ( <Container> <Row key={id}> <Col> <p>id={id}</p> <p>headline={headline}</p> </Col> </Row> </Container> )) }
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
是的,您可以混合使用ES6和ES5 - ES6完全向后兼容,因此基本上您可以将整个应用程序视为ES6,但仅在新代码中使用新的语法和功能。 您需要在您的gulp管道中添加一个转换步骤,以便通过babel传递您的代码并将其编译为ES5。 像这样的东西: var gulp = require('gulp'); var browserify = require('gulp-browserify'); var concat = require('gulp-concat'); var babel = require(' ...
-
ES6地图在Typescript(ES6 Map in Typescript)[2024-02-16]
编辑(2016年4月25日):以下答案是旧的,不应被视为最佳答案。 TypeScript现在支持“本地”地图,因此只需输出ES6即可使用ES6 Maps。 对于ES5,它不提供聚合物; 你需要自己嵌入它们。 有关更多信息,请参阅下面的mohamed hegazy的答案,以获得更现代的答案,甚至是一个简短版本的这个reddit评论 。 从1.5.0测试版开始,TypeScript尚不支持Maps 。 也不是路线图的一部分。 当前最好的解决方案是一个具有类型键和值的对象(有时称为hashmap)。 对于具有类型 ... -
ES6 React绑定更改(ES6 React bind on change)[2023-04-18]
来自React Docs : 挂载:componentDidMount void componentDidMount() 在初始渲染发生后立即仅在客户端(不在服务器上)调用一次。 在生命周期的这一点上,您可以访问子项的任何引用(例如,访问底层DOM表示)。 子组件的componentDidMount()方法在父组件之前调用。 因此,在初始渲染发生后, componentDidMount仅在生命周期中被调用一次 - 使用当前设置,在您点击刷新之前将不再有AJAX调用。 您将不得不思考使用ComponentWi ... -
如何使用ES6与本机反应(how to use ES6 with react native)[2022-08-12]
我不认为你可以通过这种方式将refs传递给组件,当然它在React不起作用,我也不认为它在React-Native会以这种方式工作。 我不清楚你为什么试图从Map组件中打开Drawer ,因为看起来Map组件只能在Drawer打开时访问,但是,如果你想从子.open中访问父行为,那么一个好的模式是通过函数让孩子们执行(你可能会认为这实际上很糟糕,并且传递事件是一种更强大的模式)。 我从来没有使用过这个库,所以我对它的用法并不完全清楚,但是你可以像这样通过函数: class Application exten ... -
有没有办法用React JSX释放ES6的全部功能?(Is there a way to unleash the full might of ES6 with React JSX?)[2023-02-22]
您可以使用Babel使用JSX编译“完整”(即我们现在拥有的)ES6 / ES2015。 您可以查看Babel的网站,了解如何操作: 如何使用JSX 。 You can use Babel to compile "full" (ie, what we have now) ES6/ES2015 using JSX. You can check out Babel's website to see how to do it: How to use JSX. -
ES6 Map:转换值(ES6 Map: transform values)[2023-06-20]
你可以使用Array.from 2 nd参数,一个map风格的回调: const positiveMap = new Map([['hello', 1],['world', 2]]), negativeMap = new Map(Array.from(positiveMap, ([k, v]) => [k, -v])); console.log([...negativeMap]); You could use the Array.from 2nd argument, a map-style ... -
当你有一个箭头函数的多个参数时,你需要在它们周围放置() 。 所以: this.state.items.map((item,i) => // ------------------^------^
- item.name
) 您的原始代码调用map作为其第一个参数,以及一个箭头函数将单个参数( i )作为其第二个参数。 您还需要在{}放入item.name , 然后将调用map到{} : renderItem(){ return(-
{th ...
-
假设id是一个数字,你可以做products.sort(({id: previousID}, {id: currentID}) => previousID - currentID) 像这样: JavaScript代码: {products .sort(({ id: previousID }, { id: currentID }) => previoudID - currentID) .map(({ id, headline }) => (
反应es6语法(React es6 grammar)[2024-04-02]
这是用ES6编写的,但这不是一个常见的React组件,它是一个无状态的 React组件,它有一些局限性。 你可以在这里阅读更多相关信息 That's written in ES6, but that's not a common React Component, that's a stateless React Component, which has some limitations. You can read more about it here相关文章
更多- sql问题
- MyBatis动态参数order by的设置
- 常用HQL(Hibernate Query Language)查询
- Mysql错误:Ignoring query to other database解决方法
- 一个sql查询
- MongoDB学习 (五):查询操作符(Query Operators).1st
- MyBatis 动态 SQL详解
- Sql Support within Solr-类Sql的solr搜索实现(1)
- 如何优化这个sql语句
- SQL中GROUP BY与HAVING的用法
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。