欢迎来到MySQL实战第77篇:修炼500篇,让我们许一个小小的目标!
【操作环境】
【实训】
1.连接查询
select 字段名 from 表1 inner|left|right join 表2 on 表1.字段名=表2.字段名 inner|left|right join 表3 on 连接条件 where 条件;
例子:
<1>内连接(两个表中都有)
select * from fruits inner join suppliers on fruits.s_id=suppliers.s_id;
<2>左连接(以左表为准)
select * from fruits left join suppliers on fruits.s_id=suppliers.s_id;
<3>右连接(以右表为准)
select * from fruits right join suppliers on fruits.s_id=suppliers.s_id;
2.as 取别名、使用case判断语句
select f_id,s_id,f_name ,case when f_price<5 then' 5元之内'when f_price between 5 and 10 then '5-10元'else '10元以上'end as 价格区间from fruits;
3.子查询
查询供应f_id=t1的水果供应商提供的水果种类。
select f_id,s_id ,f_name from fruits where s_id=(select s_id from fruits where f_id='t1');
求关注,修炼500篇,我们能熟练运用MySQL!,