岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的如何从MySQL数据库表中检索数据,希望大家看完后能赶快学习起来。
【 tulaoshi.com - 编程语言 】
那么我们如何从数据库表中检索数据呢?mysql select * from mytable; +----------+------+------------+----------+ | name | sex | birth | birthaddr | +----------+------+------------+--------+ | abccs |f | 1977-07-07 | china | | mary |f | 1978-12-12 | usa | | tom |m | 1970-09-02 | usa | +----------+------+------------+----------+ 3 row in set (0.00 sec)
mysql select * from mytable where name = "tom"; +--------+------+------------+------------+ | name |sex | birth | birthaddr | +--------+------+------------+------------+ | tom |m | 1973-09-02 | usa | +--------+------+------------+------------+ 1 row in set (0.06 sec)
mysql SELECT * FROM mytable WHERE sex = "f" AND birthaddr = "china"; +--------+------+------------+------------+ | name |sex | birth | birthaddr | +--------+------+------------+------------+ | abccs |f | 1977-07-07 | china | +--------+------+------------+------------+ 1 row in set (0.06 sec)
mysql SELECT name FROM mytable; +----------+ | name | +----------+ | abccs | | mary | | tom | +----------+ 3 row in set (0.00 sec)
mysql SELECT name, birth FROM mytable ORDER BY birth; +----------+------------+ | name | birth | +----------+------------+ | tom | 1973-09-02 | | abccs | 1977-07-07 | | mary | 1978-12-12 | +----------+------------+ 3 row in set (0.00 sec)
mysql SELECT name, birth FROM mytable ORDER BY birth DESC; +----------+------------+ | name | birth | +----------+------------+ | mary | 1978-12-12 | | abccs | 1977-07-07 | | tom | 1973-09-02 | +----------+------------+ 3 row in set (0.00 sec)
mysql SELECT COUNT(*) FROM mytable; +----------+ | COUNT(*) | +----------+ | 3 | +----------+ 1 row in set (0.06 sec) 员工中男女数量: mysql SELECT sex, COUNT(*) FROM mytable GROUP BY sex; +------+----------+ | sex | COUNT(*) | +------+----------+ | f | 2 | | m | 1 | +------+----------+ 2 row in set (0.00 sec)
来源:http://www.tulaoshi.com/n/20160219/1617607.html
看过《如何从MySQL数据库表中检索数据》的人还看了以下文章 更多>>