How do I give a NULL cell a value during select
Can I assign a static value to NULL during a sel开发者_运维百科ect statement in MySQL?
I would like any NULL values to be presented as 'not available' instead and have the ORDER BY handle the cell as 'not available' instead of NULL as well.
You can use COALESCE( column, 'not available' ) which returns the string 'not available' if column is null (in fact, it returns the first non-null argument).
Use this instead of field
:
SELECT
IF(field IS NULL, "not available", field) AS f,
...
...
ORDER BY f
You could use the COALESCE(..)
function. It returns the first non-null value, i.e.
COALESCE(myfied, 'Not available')
will return not available
if myfield
is NULL.
精彩评论