1

我有一个查询,我想按字段顺序显示结果

$sqlse .= "SELECT ".$tableColumn. " FROM ".$table." WHERE ".$where." AND ".$table2.".account_id IN (353,176,9) OR NOT IN".$table2.".account_id IN (353,176,9)  ORDER BY FIELD(account_id,353,176,9)";

我想按顺序显示结果

account_id             Name

353                    sandy
176                    Abhi
9                      jill
42                     prahsnt
435                    jack

但它按顺序显示结果

42                     prashant
435                    jack
353                    sandy
176                    abhi
9                      jill
4

2 回答 2

1

因为如果在传递给函数的列表中找不到值,它会返回FIELD0

尝试这个:

... ORDER BY FIELD(account_id, 9 , 176, 353) DESC
于 2013-09-30T07:58:23.753 回答
0
"SELECT ".$tableColumn. " FROM ".$table." WHERE ".$where." AND 
 ".$table2.".account_id IN (353,176,9)".
"UNION ALL".
"SELECT ".$tableColumn. " FROM ".$table." WHERE ".$where." AND 
 ".$table2.".account_id NOT IN (353,176,9)";
于 2013-09-30T07:57:13.507 回答