admin管理员组

文章数量:1313121

If we have the following set of data

CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 values(1,1);
INSERT INTO t1 values(1,0);

And run the query

SELECT 
  IIF(b > 0, a / b, NULL) AS c
FROM t1
ORDER BY b DESC

We get the c column as a numeric field and all is happy with the world. However, if I reverse the order, the first field is NULL, and the column is now a STRING.

SELECT 
  IIF(b > 0, a / b, NULL) AS c
FROM t1
ORDER BY b ASC

I can use 0 instead of NULL in the expression, which solves the problem of the column type, but alters the result of the query.

Is there a way I can still have NULL values, but the column is interpreted as a REAL or INT where the first record is NULL?

本文标签: