我有以下我的表中的 「設備」MySQL的CONCAT返回NULL,如果任何字段包含NULL
affiliate_name affiliate_location model ip os_type os_version
cs1 inter Dell 10.125.103.25 Linux Fedora
cs2 inter Dell 10.125.103.26 Linux Fedora
cs3 inter Dell 10.125.103.27 NULL NULL
cs4 inter Dell 10.125.103.28 NULL NULL
數據我下面的查詢執行
SELECT CONCAT(`affiliate_name`,'-',`model`,'-',`ip`,'-',`os_type`,'-',`os_version`) AS device_name
FROM devices
返回結果如下
cs1-Dell-10.125.103.25-Linux-Fedora
cs2-Dell-10.125.103.26-Linux-Fedora
(NULL)
(NULL)
給出
如何走出這使得它應該忽略NULL和結果應該是
cs1-Dell-10.125.103.25-Linux-Fedora
cs2-Dell-10.125.103.26-Linux-Fedora
cs3-Dell-10.125.103.27-
cs4-Dell-10.125.103.28-
您的解決方案也工作,但它包含的代碼量好。然而由Gerry給出的其他解決方案包含更少的代碼...不介意:) – neeraj
雖然這個答案是完全更好,夥計。 Duuuude! – Ben
這個答案是不是更靈活的選擇一個+1 – etherous