常用Mysql

发表于:2023-09-15 06:18mysql热度:47喜欢:0

查询每个title的最大num

复制代码
SELECT * from (SELECT max(num) as num,title FROM wb_rank WHERE time >= '2021-01-01 00:00:00' GROUP BY title) df ORDER BY num desc

查询a表中不存在b表的内容

mysql 复制代码
SELECT
	a.id 
FROM
	v9_download a 
WHERE
	NOT EXISTS ( SELECT * FROM v9_download_data b WHERE b.id = a.id );

mysql创建用户

复制代码
CREATE USER 'username' @'%' IDENTIFIED BY 'password';

查看权限

复制代码
SHOW GRANTS FOR 'question' @'%';

赋予部分权限

为harrison提供db1数据库的table1表SELECT(查询)、INSERT(新增)、UPDATE(修改)权限

复制代码
GRANT 
	SELECT,
	INSERT,
	UPDATE ON db1.table1 TO "harrison" @'%';

赋予db1的所有 全部增删改查权限

复制代码
GRANT ALL PRIVILEGES ON db1.* TO "username" @'%';