0

我有以下 MySQL 查询:

SELECT * FROM members_family_view ORDER BY `agelastsept` ASC

它返回以下结果:

在此处输入图像描述

我希望能够更改为显示目的返回的数据,以便 agelastsept 不显示 7,而是显示 U8,8 显示 U9,10 显示 U11,11 显示 U12,12 显示 U13,13 显示 U14。

这在 MySQL 查询中可能吗?

4

3 回答 3

2

You simply need to concatenate:

SELECT
    CONCAT("U", agelastsept + 1, "'s") AS 'agelastsept',
    total
FROM members_family_view 
ORDER BY `agelastsept` ASC
于 2013-05-14T12:34:07.463 回答
2

try this query

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

SQL FIDDLE:

| NAME | TOTAL |
----------------
| U2's |    50 |
| U3's |    55 |
| U4's |    89 |
于 2013-05-14T12:35:19.117 回答
0
Select CONCAT("U", (agelastsept + 1 ), "'s")  as agelastsept,total FROM members_family_view ORDER BY `agelastsept` ASC
于 2013-05-14T12:36:31.643 回答