mysql GROUP BY产品

|
table:
id   p_name      p_price
1    tan           1
2    soap          1
3    pro tan 01    2 
4    pro tan 02    3 
5    pro tan 03    4
如何将包含
pro tan
的产品归类,这是我想要的html结果
product name     price
tan                1
soap               1
pro tan            9
的PHP:
$q_products = $db->query(\"SELECT * FROM p_products 
                          GROUP BY p_name 
                          HAVING LIKE \'pro tan%\'\"); 
// follow by while loop for echoing
已邀请:
select s.p_name, sum(s.p_price) 
from 
  (select left(p_name, 7) as p_name, 
   p_price from products) s
group by s.p_name;
应该做你想做的。
好的,我还不能发表评论,但是尝试一下
$q_products = $db->query(\"SELECT * FROM p_products GROUP BY p_name having p_name LIKE \'pro tan%\'\");

要回复问题请先登录注册