我正在使用sql将这样的表拉到一起:
person flavour purchase
andy likes-orange_hates-vanilla $5
george likes-orange_hates-icecream $5
gena likes-vanilla_hates-bourban $2
gena likes-vanilla_hates-bourban $4
是否有可能从那里开始:
total
likes-orange $10
likes-vanilla $6
更好的是
total av. purchase size av. purchases per person total people
likes-orange $10 $5 1 2
likes-vanilla $6 $3 2 1
我只能访问phpmyadmin。
答案 0 :(得分:10)
尝试
select substring_index(flavor,'_',1), sum(purchase) from table group by 1
答案 1 :(得分:0)
在SQL 2005 +
中可以使用以下内容:
Select Tbl1.Email, Count(1) FROM (
Select substring(EmailAdd,CHARINDEX('@',EmailAdd),Len(EmailAdd)-CHARINDEX('@',EmailAdd)) as 'Email'
from TableName
) Tbl1 Group By Tbl1.Email