我运行以下选择查询
“选择名称作为名称,将Score1选为Sem1,将Score2选为Sem2,将Score3作为Sem3从表”
此处Score1,Score2,Score3中包含数值。目前我得到的数据如下
Name Sem1 Sem2 Sem3
Rohit 75 68 92
Rahul 85 79 66
Joy 80 45 81
我需要查询来抛出以下输出。
Name Sem1 Sem2 Sem3
Rohit 75% 68% 92%
Rahul 85% 79% 66%
Joy 80% 45% 81%
请您为我提供解决方案。
提前致谢..
答案 0 :(得分:4)
您需要做的就是:将%
字符串连接到指定的字段。
所以,
使用MySQL CONCAT()功能。
"Select Name as Name, CONCAT(Score1, '%') as Sem1, CONCAT(Score2, '%') as Sem2, CONCAT( Score3, '%') as Sem3 from table"
答案 1 :(得分:2)
尝试在mysql中使用CONCAT函数
Select Name as Name, CONCAT(Score1,'%') as Sem1, CONCAT(Score2,'%') as Sem2, CONCAT(Score3,'%') as Sem3 from table
答案 2 :(得分:1)
SELECT
Name AS Name,
CONCAT(Score1, '%') AS Sem1,
CONCAT(Score2, '%') AS Sem2,
CONCAT(Score3, '%') AS Sem3
FROM table
参考:http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
答案 3 :(得分:0)
您正在寻找SQL中的CONCAT功能。
Select Name as Name, CONCAT(Score1, '%') as Sem1, CONCAT(Score2 as Sem2, '%'), CONCAT(Score3 as Sem3, '%') from table;
答案 4 :(得分:0)
你可以为sql-query的结果添加一个后缀,如下所示:
SELECT Name AS Name, Score1 & " %" AS Sem1, Score2 & " %" AS Sem2, Score3 & " %" AS Sem3 FROM table
我希望这有帮助!
答案 5 :(得分:0)
使用CONCAT
Select Name as Name, CONCAT(Score1,'%') as Sem1, CONCAT(Score2,'%') as Sem2, CONCAT(Score3,'%') as Sem3 from table