mysql查询非重复的行内容,不重复的记录数count(distinct xx)

mysql查询非重复的行内容,不重复的记录数count(distinct xx)

count去重

id, p_id, p_name , p_content , p_time

1 343 aaa aaaaaa 2012-09-01

2 344 bbb bbbbbb 2012-09-02

3 321 ccc cccccccc 2012-09-03

4 343 aaa aaaaaa 2012-09-04

想查询不重复的行的内容,并且输出 p_sum ( 产品p_id出现重复的次数)

select  *, count(*) as p_sum from p_table_name group by p_name;

查询不重复的行的总行数(好写翻页)

select count(distinct p_id) as num from p_table_name;