Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 15:40:37
Original
1078 people have browsed it

有这么一个表 记录了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;


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!