
sql语句学习
wmmmyyyyyy
这个作者很懒,什么都没留下…
展开
-
创建一个表
create table actor( actor_id smallint(5) primary key not null comment '主键id', first_name varchar(45) not null comment '名字', last_name varchar(45) not null comment '姓氏', last_update date not null comment '日期');注释使用comment...原创 2021-06-29 21:15:17 · 172 阅读 · 0 评论 -
用于排序的窗口函数
1、RANK()在计算排序时,若存在相同位次,会跳过之后的位次。例如,有3条排在第1位时,排序为:1,1,1,4······2、DENSE_RANK()这就是题目中所用到的函数,在计算排序时,若存在相同位次,不会跳过之后的位次。例如,有3条排在第1位时,排序为:1,1,1,2······3、ROW_NUMBER()这个函数赋予唯一的连续位次。例如,有3条排在第1位时,排序为:1,2,3,4······窗口函数用法:<窗口函数> OVER ( [PARTITION BY <原创 2021-06-28 19:45:26 · 423 阅读 · 0 评论 -
count(*),count(列名),count(1)区别
讲解转载 2021-06-28 11:22:06 · 99 阅读 · 0 评论 -
三表连接查询
select e.last_name,e.first_name,d.dept_namefrom employees as eleft join dept_emp as de on e.emp_no=de.emp_noleft join departments as d on de.dept_no=d.dept_no;原创 2021-06-28 10:52:45 · 609 阅读 · 0 评论 -
round
在mysql中,round函数用于数据的四舍五入,它有两种形式:1、round(x,d) ,x指要处理的数,d是指保留几位小数这里有个值得注意的地方是,d可以是负数,这时是指定小数点左边的d位整数位为0,同时小数位均为0;2、round(x) ,其实就是round(x,0),也就是默认d为0;下面是几个实例1、查询: select round(1123.26723,2); 结果:1123.272、查询: select round(1123.26723,1); 结果: 1123.33转载 2021-06-21 21:26:36 · 207 阅读 · 0 评论 -
group by和having
having跟在group by后面进行过滤例子:select number from gradegroup by numberhaving count(number)>=3;原创 2021-06-21 21:17:54 · 86 阅读 · 0 评论 -
replace
replace的用法:UPDATE tbl_name SET field_name = REPLACE(field_name, string_to_find, string_to_replace)WHERE conditions;转载 2021-06-21 21:11:49 · 114 阅读 · 0 评论 -
inner join,left join,right join
left join(左联接) :返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只返回两个表中联结字段相等的行...原创 2021-06-16 21:04:07 · 93 阅读 · 0 评论 -
limit 和offset
以下的两种方式均表示取2,3,4三条条数据。1.select* from test LIMIT 1,3;当limit后面跟两个参数的时候,第一个数表示要跳过的数量,后一位表示要取的数量。2.select * from test LIMIT 3 OFFSET 1;(在mysql 5以后支持这种写法)当 limit和offset组合使用的时候,limit后面只能有一个参数,表示要取的的数量,offset表示要跳过的数量 。...原创 2021-06-16 20:46:54 · 418 阅读 · 0 评论