[英]Select all first record matching first unique word
I have the following data that looks similar to this: 我有以下看起来与此相似的数据:
id property position
======== ======== ========
1 Cool Leader
2 Cool Sponsor 1
3 Cool Sponsor 2
4 Cool Sponsor 3
5 Hot Icon
6 Hot Sponsor 2
7 Hot Sponsor 3
I am attempting to write a query that returns rows of the unique position values but ignores the number after the position. 我正在尝试编写一个查询,该查询返回唯一位置值的行,但忽略该位置后的数字。 So if Sponsor 1 exists then do not return rows where there is Sponsor 2 and Sponsor 3.
因此,如果存在发起人1,则不要返回存在发起人2和发起人3的行。
I expect the results to be: 我希望结果是:
id property position
======== ======== ========
1 Cool Leader
2 Cool Sponsor 1
5 Hot Icon
6 Hot Sponsor 2
How can I do this? 我怎样才能做到这一点?
Using MySql 使用MySql
If you want to get the first occurrence of the string 如果要获取字符串的首次出现
SELECT property, position, SUBSTRING_INDEX(position, " ", 1) AS p2
FROM table_name
GROUP BY p2, property;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.