分组MySQL结果

时间:2013-05-14 12:30:54

标签: mysql

我有以下MySQL查询:

SELECT * FROM members_family_view ORDER BY `agelastsept` ASC

返回以下结果:

enter image description here

我希望能够更改返回的数据用于显示目的,这样代替agelastsept显示7它将显示U8,8显示U9,10显示U11,11显示U12,12显示U13和13将显示U14的。

这在MySQL查询中是否可行?

3 个答案:

答案 0 :(得分:2)

你只需要连接:

SELECT
    CONCAT("U", agelastsept + 1, "'s") AS 'agelastsept',
    total
FROM members_family_view 
ORDER BY `agelastsept` ASC

答案 1 :(得分:2)

尝试此查询

select concat('U', (id+1), '\'s') as Name, total from tbl

SQL FIDDLE

| NAME | TOTAL |
----------------
| U2's |    50 |
| U3's |    55 |
| U4's |    89 |

答案 2 :(得分:0)

Select CONCAT("U", (agelastsept + 1 ), "'s")  as agelastsept,total FROM members_family_view ORDER BY `agelastsept` ASC