xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

SQL 查询语句: 模糊查询 All In One

SQL 查询语句: 模糊查询 All In One

SQL 查询语句,用户名字是以'X'开头的所有用户


select employee_id, 
IF(
  MOD(employee_id, 2) != 0 AND name NOT LIKE 'M%',
  salary,
  0
) as bonus 
from Employees 
Order By employee_id

# IF(条件,条件成立返回的内容,条件不成立返回的内容)

/*


SELECT 
    employee_id,
IF(MOD(employee_id,2)!=0 AND LEFT(name,1)!='M',salary,0) bonus
FROM Employees
ORDER BY employee_id


SELECT 
    employee_id,
    CASE 
        WHEN MOD(employee_id,2)!=0 AND LEFT(name,1)!='M' THEN salary
        WHEN MOD(employee_id,2)=0 OR LEFT(name,1)='M' THEN 0
        ELSE 0 -- 这里ELSE可以省略
    END AS bonus
FROM Employees
ORDER BY employee_id
*/

https://leetcode.cn/problems/calculate-special-bonus/

https://leetcode.cn/problems/calculate-special-bonus/submissions/

SQL 注释


# SQL 单行注释

/*

SQL 多行注释

SQL 多行注释

*/

LIKE

模糊匹配

SELECT * FROM users  WHERE user.name LIKE 'X%'

https://www.runoob.com/sql/sql-like.html

LEFT

select * from users  where left(user.name, 1)='X'

LEFT(str,len)

返回最左边的n个字符的字符串str,或NULL如果任何参数是NULL。

https://www.yiibai.com/sql/sql-left-function.html
https://www.begtut.com/sql/func-mysql-left.html

RIGHT(ARG,LENGTH)

https://www.begtut.com/sql/func-mysql-right.html

https://www.cnblogs.com/luxd/p/5976744.html

SQL 函数

SQL 拥有很多可用于计数和计算的内建函数。

SQL Aggregate 函数

SQL Scalar 函数

runoob.com/sql/sql-function.html

https://www.runoob.com/sql/sql-func-mid.html

https://www.runoob.com/sql/sql-func-left.html
https://www.runoob.com/sql/sql-func-right.html

https://www.runoob.com/sql/sql-func-last.html

exists

https://www.runoob.com/sql/sql-exists.html

demos

SQL 查询语句,名字不是以'M'开头

写出一个SQL 查询语句,计算每个雇员的奖金。
如果一个雇员的id是奇数并且他的名字不是以'M'开头,那么他的奖金是他工资的100%,否则奖金为0。



https://leetcode.cn/problems/calculate-special-bonus/?plan=sql&plan_progress=sjohlim

https://leetcode.cn/study-plan/sql/?progress=sjohlim

refs

SQL 通配符

https://www.runoob.com/sql/sql-wildcards.html

SQL 快速参考

https://www.runoob.com/sql/sql-quickref.html

SQL 视图(Views)

https://www.runoob.com/sql/sql-view.html

SQL 约束(Constraints)

https://www.runoob.com/sql/sql-constraints.html



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-10-09 22:21  xgqfrms  阅读(221)  评论(3编辑  收藏  举报