随笔分类 -  mysql

摘要:GROUP BY actor_id, director_id:按照 actor_id 和 director_id 的组合进行分组,这样可以将每个演员和导演的合作记录归为一组。 HAVING COUNT(*) >= 3:对每个分组进行统计,筛选出记录数量大于等于 3 的分组,也就是合作次数大于等于 3 阅读全文
posted @ 2025-04-16 16:29 胖豆芽 阅读(10) 评论(0) 推荐(0)
摘要:#插入数据insert into dept3 values(70,'a','aloc') 阅读全文
posted @ 2025-04-16 11:52 胖豆芽 阅读(16) 评论(0) 推荐(0)
摘要:注意 drop属于 DDL 数据库定义语言, 对象是表结构 delete属于DML 数据操作语言,对表中某行数据操作,不会动表结构。 #复制表并对其添加一列create table dept3 select * from dept2;alter table dept3 add column happ 阅读全文
posted @ 2025-04-16 11:39 胖豆芽 阅读(35) 评论(0) 推荐(0)
摘要:update salary set sex=if(sex='m','f','m') 三元表达式 if(条件1,条件2,条件3) 如果第一个条件为真 执行第二个条件 如果第一个条件为假 执行第三个条件 阅读全文
posted @ 2025-04-15 19:53 胖豆芽 阅读(13) 评论(0) 推荐(0)
摘要:# 只出现一次的最大数 num 8 8 2 2 5 5 2 7 结果是7 num 8 8 2 2 5 5 1 1 结果是null select max(num) as num from mynumbers where num in ( select num from mynumbers group 阅读全文
posted @ 2025-04-15 19:23 胖豆芽 阅读(10) 评论(0) 推荐(0)
摘要:#找出没有销售过red公司产品的销售员select namefrom salespersonwhere sales_id not in( select sales_id # 在订单表找到了公司包含red的销售的id from orders where com_id in ( # 在公司表找到了red 阅读全文
posted @ 2025-04-15 18:39 胖豆芽 阅读(15) 评论(0) 推荐(0)
摘要:# 下单最多的顾客的idorder_number customer_number1 12 23 34 3select customer_number from ordersgroup by customer_number # 对顾客进行分组order by count(customer_number 阅读全文
posted @ 2025-04-15 15:23 胖豆芽 阅读(23) 评论(0) 推荐(0)
摘要:0.搭建测试环境 创建学习用的数据库 1.数据库和sql desc 查询表结构 select version(); 查数据库的版本号 查询当前使用的数据库 2.查询基础 2.1 select基础 #查员工的月薪和年薪select ename,sal,sal*12 as '年薪'from emp; # 阅读全文
posted @ 2025-04-15 11:53 胖豆芽 阅读(12) 评论(0) 推荐(0)
摘要:游戏玩法分析 查询玩家2025年1月后 第一次登录平台的时间activity 表player_id device_id event_date games_played1 2 2025-03-01 51 2 2025-05-01 62 3 2017-05-01 3 select player_id,m 阅读全文
posted @ 2025-04-14 19:30 胖豆芽 阅读(17) 评论(0) 推荐(0)
摘要:注意不可以使用id作为条件, 因为id的自增不一定和日期百分百对应。业务逻辑要求的是日期。 上升的温度 第二天的温度大于第一天的天气的idid recorddate temperature1 2025-01-01 102 2025-01-02 253 2025-01-03 204 2025-01-0 阅读全文
posted @ 2025-04-14 19:07 胖豆芽 阅读(7) 评论(0) 推荐(0)
摘要:删除重复的电子邮箱 person 人员表id email1 j@j.com2 b@j.com3 j@j.com delete p1from person p1join person p2on p1.email=p2.email and p1.id>pe.id删除 最邮箱序号大的表对同一个表做表联合用 阅读全文
posted @ 2025-04-14 18:26 胖豆芽 阅读(13) 评论(0) 推荐(0)
摘要:顾客表 customersid name id name1 joe2 henry3 sam4 max订单表 ordersidcustomeridid customerid1 32 1 求没有下单的顾客select c.name as customersfrom customers cleft joi 阅读全文
posted @ 2025-04-14 18:03 胖豆芽 阅读(18) 评论(0) 推荐(0)
摘要:id email1 a@b.com2 c@b.com3 a@b.com 求重复的电子邮箱select emailfrom(select email,count(email) as email_countfrom persongroup by email ) as ewhere email_count 阅读全文
posted @ 2025-04-14 14:19 胖豆芽 阅读(9) 评论(0) 推荐(0)
摘要:/*雇员表 包含4列 雇员id ,姓名,工资,经理id,写找出工资比经理高的员工姓名 employee id name salary managerid 1 joe 7000 3 2 henry 8000 4 3 sam 6000 null 4 max 9000 null */ select e.n 阅读全文
posted @ 2025-04-14 13:40 胖豆芽 阅读(11) 评论(0) 推荐(0)
摘要:select a.姓名,b.城市,b.州 from a left join b on a.人员id=b.人员id; 解释 左连接的意思就是保留左表的全部数据,如果右表有空数据返回null 右连接的表示保留右表的全部数据,如果左表右空数据返回null 阅读全文
posted @ 2025-04-14 12:37 胖豆芽 阅读(8) 评论(0) 推荐(0)
摘要:先根据自己的第六感猜测数据库的密码 myslq -u root -p123456 成功的话查询端口 show global variables like 'port' 阅读全文
posted @ 2025-01-06 13:14 胖豆芽 阅读(12) 评论(0) 推荐(0)
摘要:-- 显示员工和上级领导 员工表的领导编号=领导表的员工编号 不能写反了 select e.empno as '员工号', e.ename as '员工姓名', e.mgr as '领导的员工号', l.ename as '领导的姓名' from emp e left join emp l on e 阅读全文
posted @ 2023-11-29 22:45 胖豆芽 阅读(19) 评论(0) 推荐(0)
摘要:select e.ENAME,d.LOC from emp e ,dept d where e.DEPTNO =d.DEPTNO and (d.LOC ='DALLAS'or d.LOC ='CHICAGO') ; 第一个语句搜索结果有 SMITH ALLEN 等很多ENAME |LOC | + + 阅读全文
posted @ 2023-11-26 21:28 胖豆芽 阅读(101) 评论(0) 推荐(0)
摘要:SELECT (select vlu from dept_1 d where dname='n' and loc='n') AS res1, (select vlu from dept_1 d where dname='y' and loc='y') AS res2; 阅读全文
posted @ 2023-11-26 20:48 胖豆芽 阅读(25) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/sunny3158/p/17663858.html 阅读全文
posted @ 2023-11-22 21:03 胖豆芽 阅读(56) 评论(0) 推荐(0)