有业务需求如下: select * from table where id IN (3,6,9,1,2,5,8,7) order by field(id,3,6,9,1,2,5,8,7); 这里直入主题,用TP的order方法写的话,可能不太好写,但是也可以写成这样 ->order("field(id,3,6,9,1,2,5,8,7)") 但是官方文档说了,当你的order排序中使用了SQL函数的时候,请使用orderRaw方法替代order 所以并不太好实现. 所以查阅资料找到
oracle 实现类似MYSQL的 find_in_set 排序,函数 decode: select * from tb_info_game where gameid in(23,20,19,26,18) order by decode(gameid,23,1,20,2,18,3,26,4,1009,5) by default7#zbphp.com 參考CDSN的帖子:http://topic.csdn.net/t/20060124/08/4532718.html 提问: -----------
今天在家看了一下linq,实践了一下书中代码,发现排序和查重的先后顺序太重要了. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LinqLearning { class Program { private static int[] GenerateLotsOfNumbers(int count) { Random generator = ); int[
1.默认下,使用select xxx where in(xx,xx)查询,返回结果是按主键排序的,如果要按in()中值的排列顺序,可以这样做: select * from talbe where id in(3,2,4,1) ORDER BY FIND_IN_SET( id, '3,2,4,1') 本文转自http://blog.chinaunix.net/uid-20304312-id-1707798.html 感谢作者
原来以为mysql可以进行这样的查询select id, list, name from table where 'daodao' IN (list); (一)注:1. table含有三个字段id:int, list:varchar(255), name:varchar(255) 实际上这样是不行的,这样只有当'daodao'是list中的第一个元素(我测试的时候貌似是第一个也是不行的,只有当list字段的值等于daodao时才是对的)时,查询才有效,否则都的不到结果,即使'dao