返回信息流1、如果某列的值为空的行会被count()忽略掉吗?为毛书上的程序是忽略掉了,可是我亲测就不对呢,我建了一个表b 如下:
+----+---------+------+
| id | address | a_id |
+----+---------+------+
| 1 | b | 1 |
| 2 | s | 3 |
| 3 | n | 10 |
| 4 | n | 3 |
| 5 | h | 7 |
| 6 | h | 3 |
| 7 | n | 3 |
| 8 | | 45 |
| 9 | g | 5 |
mysql> select count(address) from b;
+----------------+
| count(address) |
+----------------+
| 9 |
明明有空值啊,结果不应该是 8 吗?我不懂了!
2,正则表达式 regexp()
address 有几个值分别是‘nanjing’ ‘hainan'
那么 select * from b where address regexp 'nan' 能匹配上面的address吗?能出来结果吗?
这是一条镜像帖。来源:北邮人论坛 / database / #7675同步于 2013/9/21
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
最近在学mysql,几个问题求指教
Angelbaby3
2013/9/21镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
1.http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_count
COUNT(expr) Returns a count of the number of non-NULL values of expr in the rows retrieved by a SELECT statement.
“某列的值为空”,准确的说是(is null),而不是(= '')
【 在 Angelbaby3 的大作中提到: 】
: 1、如果某列的值为空的行会被count()忽略掉吗?为毛书上的程序是忽略掉了,可是我亲测就不对呢,我建了一个表b 如下:
: +----+---------+------+
: | id | address | a_id |
: ...................
2.http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
建议自己实践,可以加深理解
【 在 Angelbaby3 的大作中提到: 】
: 1、如果某列的值为空的行会被count()忽略掉吗?为毛书上的程序是忽略掉了,可是我亲测就不对呢,我建了一个表b 如下:
: +----+---------+------+
: | id | address | a_id |
: ...................
我实践过了 无论怎么匹配都不出现结果。
select * from b where address regexp('^nan')
select * from b where address regexp('nan*')
select * from b where address regexp('n(\w+)')
这是我匹配的sql语句,结果都是empty
【 在 doubleKO 的大作中提到: 】
: 2.http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
: 建议自己实践,可以加深理解
: