1、常用sql语句分享
2、数据库SQL 某字段按首字母排序
使用FIND_IN_SET实现按顺序查询数据需求
- sql如下:
java
select `id`, `question` from `question_answer` where `id` in (16, 274, 15, 19) and `question_answer`.`deleted_at` is null order by FIND_IN_SET( 'id', ' 16, 274, 15, 19')
- 在php中用法如下
java
DB::table('user_question_click_log')->whereIn('id',$ques_ids )
->orderByRaw('FIND_IN_SET( id, "'.implode(',',$ques_ids). '" )')
->pluck('question')