一套sql面试题的mysql解法
2023-09-11 14:18:11 时间
1.表T(a,b,c,d),要根据字段c排序后取第21—30条记录显示,请给出sql
select * from T order by c [desc] limit 20,10
2.表T(a,b,c,d)和表T1(a1,b1,c1,d1),表T中a字段是T1中的a1的外键,请用T1表中的c1,d1更新表T的c,d.
update T inner join (select a1,c1,d1 from T1) temp on t.a = temp.a1 set t.c = temp.c1,t.d = temp.d1
3.已知表ODM_JYBB有year、month和am字段,如下
Year | Month | am |
2010 | 01 | 1.1 |
2010 | 02 | 1.2 |
2010 | 03 | 1.3 |
2010 | 04 | 1.4 |
2011 | 01 | 2.1 |
2011 | 02 | 2.2 |
2011 | 03 | 2.3 |
2011 | 04 | 2.4 |
通过SQL查询转换成如下格式
Year | M01 | M02 | M03 | M04 |
2010 | 1.1 | 1.2 | 1.3 | 1.4 |
2011 | 2.1 | 2.2 | 2.3 | 2.4 |
select temp.Year as Year, group_concat(case when temp.Month = '01' then temp.am end) as 'M01', group_concat(case when temp.Month = '02' then temp.am end) as 'M02', group_concat(case when temp.Month = '03' then temp.am end) as 'M03', group_concat(case when temp.Month = '04' then temp.am end) as 'M04' from ODM_JYBB temp group by Year
4.通过SQL查询当前时间,显示格式如下所示
日期(data) | 日期(string) | 星期 | 月份 | 第几周 | 是否工作日 |
2019-10-10 10:10:10 | 2019-10-10 10:10:10 | 五 | 2019-10 | 41 | 是 |
select now() as '日期(date)', date_format(now(),'%Y-%m-%d %T') as '日期(string)', CASE dayofweek(now()) when '1' then '日' when '2' then '一' when '3' then '二' when '4' then '三' when '5' then '四' when '6' then '五' when '7' then '六' else '' end as '星期', date_format(now(),'%Y-%m') as '月份', EXTRACT(week from now()) as '第几周', if(dayofweek(ADDDATE(now(),0))%7=1 or dayofweek(ADDDATE(now(),0))%7=0,"否","是") as 是否工作日
5.一个叫 team 的表,里面只有一个字段 name, 一共有 4 条纪录,分别是 a,b,c,d, 对应四个球对,现在四个球对进行比赛,用一条 sql 语句显示所有可能的比赛组合.
select t1.name as name01, t2.name as name02 from team t1 inner join team t2 on t1.name < t2.name order by t1.`name`
相关文章
- Error connecting to database [Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)]
- 渗透测试MySQL扩展UDF后门原理与代码编写
- MySQL在线实现主从配置
- 磁盘爆满导致MySQL无法启动:Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space...
- 【MySQL】Can't get stat of './mysql/slow_log.CSV' (Errcode: 2)
- mysql优化
- MySQL中这14个必备神器,用过都说好
- PHP+Mysql防止SQL注入的方法
- Centos 实战-MySQL定时全量备份(1)
- 连接Mysql提示Can’t connect to local MySQL server through socket的解决方法
- 【转载】低成本和高性能的MySQL云数据库的实现淘宝 MySQL
- Linux + apache + php + mysql
- MySQL操作之JSON数据类型操作详解
- MYSQL避免全表扫描__如何查看sql查询是否用到索引(mysql)
- Mysql 如果有多个可选条件怎么加索引_MySQL|mysql-索引
- MySQL最后一次查询耗时查询
- MYsql 数据库密码忘记(Window)-2(mysql 5.7)
- Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).
- Python MySQL - mysql-connector 驱动
- MySQL面试题——in是否使用【索引】
- PHP面试题:mysql_fetch_row() 和mysql_fetch_array之间有什么区别?
- mysql事务 mysql事务回滚 MySQL事务死锁 如何解除死锁 资金出入账
- mysql优化方法积累
- MySQL Study之--Mysql无法启动“mysql.host”
- mysql的order by注入
- Mysql数据库的mysql Schema 究竟有哪些东西& 手工注入的基础要领
- mysql 查看 脏页_MySQL:刷脏页
- MySQL缺失mysql_config文件
- mysql优化
- mysql索引优化策略有哪些
- Mysql报错:Can't connect to local MySQL server through socket '/tmp/mysql.sock'