问题
I need to put a Case in the Select to check if the Data I'm adding to my view is NULL, in which case I want it to just enter a zero, or not.
回答1:
You mean something like this?
SELECT IF(`field` IS NULL, 0, `field`)...
There's also "IFNULL()":
SELECT IFNULL(`field`, 0)...
回答2:
select coalesce(field, 0) as 'field' from v;
(doc)
回答3:
When creating your table just add NOT NULL to the column description, e.g.
CREATE TABLE (
ID INT NOT NULL default '0'
);
Then if no data is given for the field it is set to the default value of 0 which will be retrieved when you run a SELECT query.
来源:https://stackoverflow.com/questions/1174850/mysql-view-check-if-data-is-null