Sgg:(LeetCode每日一题)--626_换座位

换座位

1 题目概述

难度:中等
Sgg:(LeetCode每日一题)--626_换座位
Sgg:(LeetCode每日一题)--626_换座位

2 思路变迁

主要说明一下case when的用法吧:

2.1 简单case函数

case sex 
	when sex = 1 then '男'
	when sex = 1 then '女'
	else '其他' end 

2.2 case when 搜索函数

CASE WHEN sex = '1' THEN '男' 
WHEN sex = '2' THEN '女' 
ELSE '其他' END  

这里说明一下,mysql是不允许不写else的,就是无论如何必须有else;
但是hive SQL是可以不写else,直接 end的。

3 代码开搂

# Write your MySQL query statement below
select
    case when mod(id,2) != 0 and id != counts then id + 1
         when mod(id,2) != 0 and id = counts then id
         else id - 1 end id,
    student
from seat, 
    (select count(*) counts from seat) seat_count
order by id;
Sgg:(LeetCode每日一题)--626_换座位Sgg:(LeetCode每日一题)--626_换座位 极度丶浚爱 发布了39 篇原创文章 · 获赞 4 · 访问量 1408 私信 关注
上一篇:五、分类模型及超参数调优


下一篇:机器学习概念