mysql多條件查詢,按傳入引數順序顯示

2021-09-13 16:33:36 字數 1028 閱讀 5935

在mysql中進行查詢,對同乙個字段,存在多個引數值進行查詢

比如在下面的表(book_table)中

idbook_name

author

nationality

1老人與海

海明威美國

2斷捨離

山下英子日本3

小王子託萬·德·聖·埃克蘇佩里

法國我們使用如下sql:

select * from book_table where id in ('2', '1', '3');

結果會是:

id book_name author nationality

1 斷捨離 山下英子 日本

2 老人與海 海明威 美國

3 小王子 託萬·德·聖·埃克蘇佩里 法國

順序仍然是按照id的公升序排列

如果我們向要在結果集中使用 2 1 3的順序,就需要對結果集也排序

select * from book_table where id in ('2', '1', '3')

order by field(id, '2', '1', '3');

結果會是:

id book_name author nationality

2 老人與海 海明威 美國

1 斷捨離 山下英子 日本

3 小王子 託萬·德·聖·埃克蘇佩里 法國

如果在mybatis的xml檔案中,可以這樣寫

select * from book_table

where id in

#order by field(id,#)

MySql 多條件查詢

ci model裡面乙個多重條件搜尋,place type thefind 三個條件初始值為空 搜尋all 在根據前端資訊設定條件 根據條件搜出進行模糊查詢 place plcae type type descrption,lostname,type thfind 資料庫 lost message表...

多條件查詢

思路 1.獲取引數值 2.生成查詢條件 3.獲取查詢結果 4.繫結查詢選項 呼叫geturlhtml方法生成查詢url 例如 var y2013 pnvshihufu qbeijing sxuhuiqu 得到url變數值 protected string geturlval string name ...

多條件查詢

多條件查詢時在做專案的時候不可缺少的功能,雖然很簡單,但是自己還是記一下,對自己有用 查詢事件 private void button查詢 click object sender,eventargs e initial catalog uid pwd this.dataserver,this.dat...