の理解ORDER BY
に問題がありMySQL
ます。3つの基準でテーブルをソートする必要があります
1 - 最初にTYPE_OF_WORKで並べ替えたいので、すべてのデータはアルファベット順でなければなりません。
dech_rap_bus
dech_rap_bus
ger_dem_dech_bus
ger_dem_dech_bus
ger_dem_stp_pp
...
結果 => http://sqlfiddle.com/#!2/b2a858/6
2 - 2 番目にPROJECT_VERSIONで並べ替えたいので、すべてのデータはアルファベット順である必要がありますが、次のように 1 の基準を尊重します。
dech_rap_bus V123-V1234
dech_rap_bus V300
ger_dem_dech_bus V123-V1234
ger_dem_dech_bus V300
ger_dem_stp_pp V123-V1234
結果 => http://sqlfiddle.com/#!2/b2a858/7
したがって、 1と2は完全に機能しています。
3 - この後、列not_existingでソートしたい
結果 => http://sqlfiddle.com/#!2/b2a858/5
そして、それが実際に何をするのかはわかりませんが、結果が表示されません...
dech_rap_bus V300
ここで、NOT_EXISTING列が1の場合は最後になり、NOT_EXISTING = 1の場合はテーブルの最後以外のすべてを並べ替えます。
2 選択の UNION が役立つだろうと自分に言い聞かせました
/* Selecting all data where not_existing is not 1 or NULL ---> working good! */
(
SELECT
*
FROM
atm_mti_view
WHERE
project_function='FRS01' AND
on_big_project_id = 12 AND
(not_existing != 1 OR not_existing IS NULL)
ORDER BY
type_of_work ASC,
project_version ASC
)
UNION
/* Selecting all data where not_existing is 1 ---> working good! */
(
SELECT
*
FROM
atm_mti_view
WHERE
project_function='FRS01' AND
on_big_project_id = 12 AND
not_existing = 1
ORDER BY
type_of_work ASC,
project_version ASC
)
しかし、このコードが行うことは、存在しない dech_rap_bus を最後に配置することです。良いのですが、バージョンの並べ替えが台無しになります。なぜですか???
ここで結果を参照してください=> http://sqlfiddle.com/#!2/b2a858/8
何故ですか?2 つの選択結果をMERGEしたいだけですが、何が間違っていますか?