Home  >  Article  >  Database  >  mysql查询不重复的行内容,不重复的记录数.count,distinct

mysql查询不重复的行内容,不重复的记录数.count,distinct

WBOY
WBOYOriginal
2016-06-07 15:40:371169browse

有这么一个表 记录了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出现重复的次数) sele

有这么一个表

记录了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;


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn