By default, MySQL sorts nulls first
だろう、私は(行が非挿入小さなテストケースを作成しました - puで並べ替えrpose)。
create table map_towns(
town varchar(30) not null
,priority int null
);
insert into map_towns(town, priority) values('d_town3', 3);
insert into map_towns(town, priority) values('a_town2', 2);
insert into map_towns(town, priority) values('c_town4', 4);
insert into map_towns(town, priority) values('b_town1', 1);
insert into map_towns(town, priority) values('b_town6', NULL);
insert into map_towns(town, priority) values('d_town8', NULL);
insert into map_towns(town, priority) values('a_town5', NULL);
insert into map_towns(town, priority) values('c_town7', NULL);
次のクエリは、あなたが求めるものを行う必要があります。ここで
select town
,priority
,isnull(priority)
from map_towns
order by isnull(priority), priority, town;
+---------+----------+------------------+
| town | priority | isnull(priority) |
+---------+----------+------------------+
| b_town1 | 1 | 0 |
| a_town2 | 2 | 0 |
| d_town3 | 3 | 0 |
| c_town4 | 4 | 0 |
| a_town5 | NULL | 1 |
| b_town6 | NULL | 1 |
| c_town7 | NULL | 1 |
| d_town8 | NULL | 1 |
+---------+----------+------------------+
は、あなたのテーブル構造としたい結果のサンプルを追加しないのはなぜ
ISNULL documentation
上のリンクである...私は完全にあなたの質問を理解してNIT確かです。 – Jaime
ORDER BY優先、town ????? –
私は答えを投稿した後、もう一度質問を再読しました。優先度= 1だけ気にしますか? priority = 1はpriority = 2より前にソートされるべきですか?たとえば、 "a_town2"が優先度= 4を取得し、 "c_town4"が優先度= 2を取得すると、最初に来ますか? – Ronnis