一.子查询--查询的嵌套(重点记忆) select MAX(age)from haha where bumen='销售部' --汇总-- select MAX(age)from haha where bumen in ( ) --参数(数值)必须是在只有1个的前提下才能用‘=’,如果参数大于1,就要用in(在...范围); select*from haha where age=( select MAX(age)from haha where bumen in ( ) ) and bumen=(s…
所谓子查询语句,就是先通过一个语句来查询出一个结果,然后再通过一个查询语句从这个结果中再次查询.子查询语句一般有以下3种.下面以一个案例来做讲解. 案例:查询[例1]中每个分类下的最新的那一条商品信息. 如果通过单句查询,是获取不到的.如下面这样是错误的: select max(goods_id),cat_id,goods_name from goods group by cat_id; 这样获取到了每个分类的最新商品ID号goods_id,但是其它信息如goods_name商品名称却是旧的那一…
语句 SELECT a.id as item_id,a.name as item_name,a.intro as item_intro,b.id,b.money FROM sh_incentive_item a left join ( SELECT * FROM `sh_incentive` WHERE ( `agent_id` = 3 ) AND ( `year` = 2016 ) AND ( `month` = 1 ) ) b on a.id = b.item_id; 如何实现 SELECT…
上一章 说了下 子查询的意义是 把一条查询语句当做值来使用 select *from car //查询汽车的信息 假设我知道一个汽车的编号是 c021 但是我要查询 比这个汽车价格高的汽车信息 先找到汽车编号是c021的 select *from car where code='c021' 在找这个汽车的价格 select price from car where code='c021' //返回的是价格这个值 这个值是 31.75 那么我要找比这个价格高的汽车信息…
一.SQL子查询语句 1.单行子查询 select ename,deptno,sal from emp where deptno=(select deptno from dept where loc='NEW YORK'): 2.多行子查询 SELECT ename,job,sal FROM EMP WHERE deptno in ( SELECT deptno FROM dept WHERE dnam…
首先,以超级管理员的身份登录oracle sqlplus sys/bjsxt as sysdba --然后,解除对scott用户的锁 alter user scott account unlock; --那么这个用户名就能使用了. --(默认全局数据库名orcl) 1.select ename, sal * 12 from emp; --计算年薪 2.select 2*3 from dual; --计算一个比较纯的数据用dual表 3.se…
--select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from student; --top 取前N条记录 s…
一:基本的查询sql 1:基本常用查询 select * from student; --select select all sex from student; --all 查询所有 select distinct sex from student; --distinct 过滤重复 --count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from stu…