2017-03-01 84 views
0

我會向你尋求幫助。 示例表:如何做這樣的mysql查詢?

| ID | NAME |POINT| 
| 1 | alex | 2 | 
| 2 | alex | 2 | 
| 3 | jenn | 4 | 
| 4 | shama| 3 | 
| 5 | jenn | 4 | 
| 6 | Mike | 1 | 

我想找到重複的名稱,並更改名稱值,總結重複值。 Like

| ID | NAME  |POINT| 
| 1 | alexander| 4 | 
| 2 | jennifer | 8 | 

是否有可能mysql查詢? 謝謝。

+0

'SUM(點)GROUP BY NAME'?但那麼ID是什麼意思 – bansi

回答

0

試試這個

select id, 
case when name = 'alex' then replace(NAME,'alex','alexander') 
    when name = 'jenn' then replace(NAME,'jenn','jennifer') 
    end as d,sum(point) 
    from name group by d having d is not null; 
+0

真的很棒@denny –

+0

謝謝你歡迎來到stackoverflow – denny

+0

如果我想使用替換字符串。選擇point_id, 如果名稱像'Alex%'那麼替換(NAME,「Ale%」,「Alexander」) 結束爲d,總和(數量) from hb_number其中,point_id = 736 group by d having d不爲null ; –

0

這是你想要的嗎?

select (@rn := @rn + 1) as id, name, sum(point) as point 
from t cross join 
    (select @rn := 0) params 
group by name 
having count(*) >= 2;