-1

happy pascal day.

('Afghanistan - Fixed'),
('Afghanistan - Mobile AWCC'),
('Afghanistan - Mobile Etisalat'),
('Afghanistan - Mobile MTN'),
('Afghanistan - Mobile Others'),
('Afghanistan - Mobile Roshan'),
('Afghanistan - Mobile WASEL'),
('Albania - Fixed'),
('Albania - Fixed ALBTEL'),
('Albania - Fixed AMC'),
('Albania - Fixed Tirana'),
('Albania - Interactive TV'),
('Albania - Mobile'),
('Albania - Mobile AMC'),
('Albania - Mobile Plus'),
('Albania - Mobile Vodafone'),
('Algeria - Fixed'),
('Algeria - Fixed CAT'),
('Algeria - Mobile Orascom'),
('Algeria - Mobile Others'), ...

I need to get Algeria, Albania and Afghanistan distinct, groupp by ?, you have idea ?

4

2 回答 2

1

如果我理解正确,你可能需要这样的东西

SELECT DISTINCT TRIM(SUBSTRING_INDEX(field1, '-', 1)) countries
FROM table1

输出:

|   COUNTRIES |
---------------
| Afghanistan |
|     Albania |
|     Algeria |

SQLFiddle 示例

这也将起作用

SELECT TRIM(SUBSTRING_INDEX(field1, '-', 1)) countries
FROM table1
GROUP BY TRIM(SUBSTRING_INDEX(field1, '-', 1))

SQLFiddle 示例

于 2013-04-01T21:34:32.553 回答
0
select distinct SUBSTRING_INDEX(text, ' - ', 1) from test;

http://www.sqlfiddle.com/#!2/ba297/3

于 2013-04-01T21:37:59.533 回答