This theme is built with awescnb.|

Little_Monster-lhq

园龄:5年9个月粉丝:26关注:18

📂MySQL
🔖Study
2022-09-10 10:51阅读: 131评论: 0推荐: 0

SQL CASE语句的使用

SQL CASE语句的使用

CASE是一个控制流语句,其作用与IF-THEN-ELSE语句非常相似,可根据数据选择值。 CASE语句遍历条件并在满足第一个条件时返回值。 因此,一旦条件成立,它将短路,从而忽略后面的子句并返回结果。 正如我们在今天的博客中看到的那样,它可以用来测试条件和离散值。

基本语法
CASE语句有两种形式:

第一种评估一个或多个条件,并返回第一个符合条件的结果。 如果没有条件是符合的,则返回ELSE子句部分的结果,如果没有ELSE部分,则返回NULL:

CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;

第二种CASE句法返回第一个value = compare_value比较结果为真的结果。 如果没有比较结果符合,则返回ELSE后的结果,如果没有ELSE部分,则返回NULL:

CASE compare_value
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;

示例:
要尝试使用CASE语句,我们将使用Navicat Premium编写一些针对Sakila示例数据库的查询。 它是一个功能强大的数据库开发和管理工具,可以同时连接到大多数主流的数据库,其中包括MySQL、MariaDB、MongoDB、SQL Server、Oracle、PostgreSQL、以及SQLite数据库。 它还兼容许多云数据库,例如Amazon RDS、Amazon Aurora、Amazon Redshift、Microsoft Azure、Oracle Cloud、Google Cloud、以及MongoDB Atlas。

语法1

这是一个选择电影标题以及它们的发行年份和租赁价格列表的查询:
在这里插入图片描述
我们将添加一个列,将租赁价格分为三类:“discount”,“regular”和“premium”。 价格范围是:

低于2.99美元
2.99-4.99美元之间
4.99美元或以上

声明:本人只是为了个人学习所用。

本文作者:Little_Monster-lhq

本文链接:https://www.cnblogs.com/little-monster-lhq/p/16676170.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Little_Monster-lhq  阅读(131)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 IVORY TOWER - 虞万殊
  2. 2 I Really Like You - Carly Rae Jepsen
  3. 3 404 not found REOL
  4. 4 不暧昧 - 徐秉龙,黄星侨
I Really Like You - - Carly Rae Jepsen
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Carly Rae Jepsen

作曲 : Carly Rae Jepsen

I really wanna stop

But I just gotta taste for it

I feel like I could fly with the ball on the moon

So honey hold my hand you like making me wait for it

I feel I could die walking up to the room, oh yeah

Late night watching television

But how we get in this position?

It's way too soon, I know this isn't love

But I need to tell you something

I really really really really really really like you

And I want you, do you want me, do you want me, too?

I really really really really really really like you

And I want you, do you want me, do you want me, too?

Oh, did I say too much?

I'm so in my head

When we're out of touch

I really really really really really really like you

And I want you, do you want me, do you want me, too?

It's like everything you say is a sweet revelation

All I wanna do is get into your head

Yeah we could stay alone, you and me, and this temptation

Sipping on your lips, hanging on by thread, baby

Late night watching television

But how we get in this position?

It's way too soon, I know this isn't love

But I need to tell you something

I really really really really really really like you

And I want you, do you want me, do you want me, too?

I really really really really really really like you

And I want you, do you want me, do you want me, too?

Oh, did I say too much?

I'm so in my head

When we're out of touch

I really really really really really really like you

And I want you, do you want me, do you want me, too?

Who gave you eyes like that?

Said you could keep them

I don't know how to act

The way I should be leaving

I'm running out of time

Going out of my mind

I need to tell you something

Yeah, I need to tell you something

Yeah I really really really really really really like you

And I want you, do you want me, do you want me, too?

I really really really really really really like you

And I want you, do you want me, do you want me, too?

Oh, did I say too much?

I'm so in my head

When we're out of touch

I really really really really really really like you

And I want you, do you want me, do you want me, too?

I really really really really really really like you

And I want you, do you want me, do you want me, too?

I really really really really really really like you

And I want you, do you want me, do you want me, too?