//多表关联查询数量select user, t1.count1, t2.count2from user tleft join ( select user_id, count(sport_type) as count1 from sport group by user_id) t1on t.id = t1.user_idleft join ( select user_id, count(level) as count2 from grade group by user_id) t2on t.id
多个表右链接查询 名字,学校名称,学校类型,城市名称,国家地区 左链接查询 子查询 索引 #创建MySQL时添加索引 mysql> create table userIndex( id int primary key, name varchar(10), address varchar(100), index indexName (name) ); #更新表的时候添加索引,使⽤的关键字是alter mysql> alter table student add index indexStu(sc
概要 本节要实现的是多表关联查询的简单demo.场景是根据id查询某商品分类信息,并展示该分类下的商品列表. 一.Mysql测试数据 新建表Category(商品分类)和Product(商品),并插入几条测试数据. create table Category ( Id int not null auto_increment, Name ) null, constraint pk_category primary key (Id) ); INSERT INTO category(Name) VAL