|
|
|
Суммирование с Null значениями
|
|||
|---|---|---|---|
|
#18+
Как правильно просуммировать 2 int поля в запросе select, если в одном из них может быть NULL. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 25.05.2005, 10:59 |
|
||
|
Суммирование с Null значениями
|
|||
|---|---|---|---|
|
#18+
Working with null Values Код: plaintext 1. The function 'COALESCE' can simplify working with null values. for example, to treat null as zero, you can use: select COALESCE(colname,0) from table where COALESCE(colname,0) > 1; in a date field, i used: ORDER BY (coalesce(TO_DAYS(date),TO_DAYS(CURDATE()))-TO_DAYS(CURDATE())) to treat NULL as the current date. Posted by Bob Kolk on January 10 2003 12:05pm [Delete] [Edit] Use IFNULL() in your SELECT statement is make the NULL any value you wish. IFNULL(expr1,expr2) If expr1 is not NULL, IFNULL() returns expr1, else it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used: mysql> SELECT IFNULL(1,0); -> 1 mysql> SELECT IFNULL(NULL,10); -> 10 mysql> SELECT IFNULL(1/0,10); -> 10 mysql> SELECT IFNULL(1/0,'yes'); -> 'yes' ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 25.05.2005, 11:27 |
|
||
|
|

start [/forum/topic.php?fid=47&fpage=657&tid=1854016]: |
0ms |
get settings: |
10ms |
get forum list: |
17ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
54ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
36ms |
get tp. blocked users: |
1ms |
| others: | 207ms |
| total: | 343ms |

| 0 / 0 |
