mysql统计数量的语句(mysql数据库的这个数据统计sql语句怎么写)

本文目录
mysql数据库的这个数据统计sql语句怎么写
create table aa(
typeId int,
name varchar(20))
create table bb(
id int ,
name varchar(20),
typeId int ,
num int ,
m int
)
insert into aa values(1,’自行车’),(2,’摩托车’),(3,’小汽车’),(4,’其它’)
insert into bb values
(1,’li’,1,1,500),
(2,’li’,2,2,5000),
(3,’li’,3,1,50000),
(4,’wanger’,1,1,450),
(5,’wanger’,2,1,5600)
select bb.name,
sum(case when aa.name =’自行车’ then bb.num
else 0
end ) as ,
sum(case when aa.name =’自行车’ then bb.m
else 0
end ) as ,
sum(case when aa.name =’摩托车’ then bb.num
else 0
end ) as ,
sum(case when aa.name =’摩托车’ then bb.m
else 0
end ) as ,
sum(case when aa.name =’小汽车’ then bb.num
else 0
end ) as ,
sum(case when aa.name =’小汽车’ then bb.m
else 0
end ) as ,
sum(case when aa.name =’其它’ then bb.num
else 0
end ) as ,
sum(case when aa.name =’其它’ then bb.m
else 0
end ) as ,
sum(bb.num) as ,
sum(bb.m ) as
from aa right join bb on aa.typeId=bb.typeId
group by bb.name
truncate table aa
drop table aa
truncate table bb
drop table bb
go
mysql 脚本的方法,请对照这个 sql server脚本去修改,如有疑问,及时沟通
mysql join查询,并统计数量
1、打开终端窗口,登录mysql。mysql -uroot -p。
2、SHOW DATABASES;USE testdb;这个时候切换到相应的数据库。
3、SHOW TABLES;INSERT INTO branch VALUES(6, ’BB’, NULL, NULL);SELECT * FROM branch;比如我们为branch这个表插入数据。
4、SELECT employee.emp_id, employee.first_name, branch.branch_nameFROM employee JOIN branch ON employee.emp_id = branch.mgr_id;这个时候进行一下数据的联合,用JOIN。
MYSQL 统计语句
select sum(ordercount) from orders where teamId = 2 这样就行了~!!~如果Teamid 是字符类型的 就的用select sum(ordercount) from orders where teamId = ’2’
mysql分类统计数量
1:SELECT SUM(总藏书量),SUM(管内剩余) FROM `藏书信息` GROUP BY 入库时间
2:SELECT SUM(总藏书量)/count(总藏书量),SUM(管内剩余)/count(管内剩余) FROM `藏书信息` GROUP BY 入库时间

更多文章:
html document对象(载入浏览器的html文档都会成为document的对象吗)
2026年9月21日 16:00
安装包怎样下载mysql(如何在官网上下载可安装版的MySQL数据库)
2026年9月21日 15:30
威廉尖叫音效在线(渴求《勇敢的心》的配乐a gift of a thistle下载)
2026年9月21日 15:20
wordpress建站教程视频(WordPress建站的基本流程)
2026年9月21日 14:00
powerquery(power query中文含义是什么)
2026年9月21日 11:50
reactnative文档扫描(为什么要学习React Native)
2026年9月21日 10:30
aptana studio 3 windows 10(aptana studio 3 怎么改成中文)
2026年9月21日 09:20





