gpt4 book ai didi

mysql - 我可以在 MySQL 中使用多个大小写吗?

转载 作者:行者123 更新时间:2023-11-29 13:13:00 25 4
gpt4 key购买 nike

要求:

原始表:SCORE

+--------+----------+-----------+
| Math | English | Chemistry |
+--------+----------+-----------+
| 69 | 82 | 95 |
+--------+----------+-----------+

排序:- [0-80] -> C- [80-90] -> B- [90-100] ->A

输出应该是

+--------+----------+-----------+
| Math | English | Chemistry |
+--------+----------+-----------+
| C | B | A |
+--------+----------+-----------+

我应该在Oracle中进行测试,但现在我首先在MySQL上进行测试。我的代码如下:

CREATE table grade1(
Math varchar(10),
English varchar(10),
Chemistry varchar(10))

INSERT INTO grade1 (Math, English, Chemistry)
VALUES (

SELECT
CASE
when Math < 80 then 'C'
when Math > 80 and Math <90 then 'B'
when Math > 90 and Math <100 then 'A'
END
FROM SCORE,

SELECT
CASE
when English < 80 then 'C'
when English > 80 and English < 90 then 'B'
when English > 90 and English < 100 then 'A'
END
FROM SCORE,

SELECT
CASE
when Chemistry < 80 then 'C'
when Chemistry > 80 and Chemistry <90 then 'B'
when Chemistry > 90 and Chemistry <100 then 'A'
END
FROM SCORE)

请检查是否有问题?因为我无法运行它。

最佳答案

这个怎么样?

INSERT INTO grade1 (Math, English, Chemistry)
VALUES (
SELECT
CASE
WHEN Math >= 90 then 'A'
WHEN Math >= 80 then 'B'
WHEN Math < 80 then 'C'
END Math,
CASE
WHEN English >= 90 then 'A'
WHEN English >= 80 then 'B'
WHEN English < 80 then 'C'
END English,
CASE
WHEN Chemistry >= 90 then 'A'
WHEN Chemistry >= 80 then 'B'
WHEN Chemistry < 80 then 'C'
END Chemistry
FROM SCORE)

您不必在每个 CASE 之前使用 SELECT。我更改了 WHEN 值的顺序。

关于mysql - 我可以在 MySQL 中使用多个大小写吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21838843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com