mysql常用

MySQL查询

select name from table_name;

select distinct name from table_name;

select name from table_name where is=1;

select name from table_name order by age desc#降续

select name from table_name limit 3SELECT * FROM table_name WHERE date_column< '2020-01-01';

上述语句将检索date_column列值小于202011日的行。

SELECT Websites.id, Websites.name, access_log.count, access_log.date
FROM Websites INNER JOIN access_log
ON Websites.id=access_log.site_id; 
# "Websites" 表中的 "id" 列指向 "access_log" 表中的字段 "site_id"


SELECT Websites.name, access_log.count, access_log.date
FROM Websites LEFT JOIN access_log
ON Websites.id=access_log.site_id  ORDER BY access_log.count DESC;

MySQL增

insert into Mans (id,name,age,will) values (1,"李明",32,"象棋,游泳");

MySQL删

delete from Womans where id=3;

MySQL改

update Mans set name="TOM",age=22 where id=1;
like 'G%'--以字母 "G" 开始的所有
between 1 and 20 --介于 1 和 20 之间
in ('Google','菜鸟教程') --"Google" 或 "菜鸟教程" 
country='CN'and alexa > 50  --国家为 "CN" 且alexa排名大于 "50" 
country='CN'or alexa > 50  --国家为 "CN" 或alexa排名大于 "50" 
ID int NOT NULL  --强制 "ID" 列不为空
primary key
default
AVG(age) - 返回平均值
MAX(age) - 返回最大值
MIN(age) - 返回最小值
SUM(age) - 返回总和
count(name)  -返回个数
group by

group by 和 having

SELECT site_id, SUM(access_log.count) AS nums
FROM access_log GROUP BY site_id; #按site_id分组后求和

SELECT Websites.name,COUNT(access_log.aid) AS nums FROM access_log
LEFT JOIN Websites
ON access_log.site_id=Websites.id
GROUP BY Websites.name;#按Websites.name分组后,多表求access_log.aid个数

SELECT Websites.name, Websites.url, SUM(access_log.count) AS nums FROM (access_log
INNER JOIN Websites
ON access_log.site_id=Websites.id)
GROUP BY Websites.name
HAVING SUM(access_log.count) > 200;

SELECT Websites.name, SUM(access_log.count) AS nums FROM Websites
INNER JOIN access_log
ON Websites.id=access_log.site_id
WHERE Websites.alexa < 200 
GROUP BY Websites.name
HAVING SUM(access_log.count) > 200; #HAVING 子句可以筛选分组后的各组数据
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值