如何使用包含一个字段的SQL查询,如果该字段包含的值为' 90' AND' 99',结果会将A连接到它?
最终输出将如下所示。
91A
92A
93A
94A
95A
我试过了。
SELECT
tblgrade.fld1stGrade ,'A'
FROM
tblgrade WHERE tblgrade.fld1stGrade BETWEEN '90' AND '99'
答案 0 :(得分:1)
如果您的实现是在SQL Server中,请尝试以下操作。
SELECT
tblgrade.fld1stGrade +'A'
FROM
tblgrade WHERE CAST(tblgrade.fld1stGrade as int) >= 90
and cast(tblgrade.fld1stGrade as int) <= 99;
对于MySQL实现,请使用以下内容。
select concat(tblgrade.fld1stGrade, 'A') from tblgrade
where tblgrade.fld1stGrade >= 90 and tblgrade.fld1stGrade <= 99;
对于MySQL中的多类别比较,请使用以下内容。
select
case
when tblgrade.fld1stGrade >=90 and tblgrade.fld1stGrade <= 99
then concat(tblgrade.fld1stGrade, 'A')
when tblgrade.fld1stGrade >=80 and tblgrade.fld1stGrade <= 89
then concat(tblgrade.fld1stGrade, 'B')
when tblgrade.fld1stGrade >=70 and tblgrade.fld1stGrade <= 79
then concat(tblgrade.fld1stGrade, 'C')
else concat(details, 'D')
end
as Grade
from supportContacts;
答案 1 :(得分:0)
你可以试试这个:
SELECT tblgrade.fld1stGrade + 'A' AS letter_grade FROM tblgrade
WHERE tblgrade.fld1stGrade BETWEEN '90' AND '99'