欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql 必知必会

程序员文章站 2022-07-12 17:52:22
...
#SHOW DATABASES
#USE user
#SELECT * FROM users ORDER BY name
#SELECT * FROM users WHERE name NOT IN ('4444','Hello World')
#SELECT * FROM users WHERE name LIKE '%4%' #百分号通配符 匹配多个
#SELECT * FROM users WHERE name LIKE '自动%4%'
#SELECT * FROM users WHERE name LIKE '4_44' #_只能替代一个字符与%能匹配0个字符不一样,_总是匹配一个字符,不能多也不能少。
#SELECT * FROM users WHERE name REGEXP '44'
#SELECT * FROM users WHERE name REGEXP '4444.1'
#SELECT * FROM users WHERE name REGEXP '4444|He' #搜索两个串之一
#SELECT * FROM users WHERE name REGEXP '[54]44'
#SELECT * FROM users WHERE name REGEXP '[:alpha:]'
#SELECT CONCAT(name,'(',age,')') AS kuohao,CONCAT(name,'&',age,'&') AS he FROM users
#USE user
#计算字段
#SELECT pro_id,quantity,item_price,quantity*item_price AS expanded_price FROM orderitems
#SELECT name,Upper(name) AS upcase_name FROM users
#SELECT * FROM users
#SELECT AVG(age) AS avg_age FROM users # 求平均数
#SELECT COUNT(*) FROM users #聚焦函数
#SELECT MAX(age) FROM users #MIN(expr)
#SELECT SUM(age) AS sumage FROM users
#select version() from users;

#分组GROUP BY
#SELECT *,COUNT(*) AS age_nums FROM users GROUP BY age #按年龄分组 顺序 where 、GROUP BY、 ORDER BY
SELECT id,COUNT(*) AS age_count FROM users GROUP BY id HAVING COUNT(*)>20