我想显示我的查询结果

时间:2013-01-29 10:43:35

标签: mysql mysql-workbench

这是我目前的结果 mysql> select * from city;

名称CountryCode区人口

bangaluru   91  bangaluru   6347673
bangaluru   91  bangaluru   347673
bangaluru   91  bangaluru   67673
andhra      91  andhra      63476
mangalore   91  mangalore   63473

这是我想要的:

名称CountryCode区人口

bangaluru   91       bangaluru  6347673
            91       bangaluru  347673
            91       bangaluru  67673
andhra      91       andhra     63476
mangalore   91       mangalore  63473

1 个答案:

答案 0 :(得分:1)

SELECT 
    CASE WHEN _no = @i THEN '' ELSE @i := _no END
    as row_no,
    _no,
    _name
FROM
(
    SELECT 1 as _no, 'vikas' as _name UNION ALL
    SELECT 1, 'kratika' UNION ALL
    SELECT 2, 'vikas' 
) t,
(SELECT @i := '') temp