简体   繁体   English

显示所有计数大于1的表记录

[英]Display all the table records whose count is greater than 1

I have a table which has category and brand as follows:我有一张表,其类别和品牌如下:

| id| category | brand |   date    | ........
| 1 |   A      | A1    | 12-DEC-09 | ........
| 1 |   A      | A1    | 12-DEC-09 |........
| 1 |   A      | A1    | 13-DEC-09 |........
| 2 |   A      | A2    | 14-DEC-09 |........
| 2 |   B      | B1    | 14-DEC-09 |........
| 2 |   B      | B2    | 14-DEC-09 |........
| 2 |   B      | B3    | 14-DEC-09 |........

I need to display the result with brand more than 1. The brand is based on category.我需要显示品牌超过 1 的结果。品牌基于类别。

I need result like this:我需要这样的结果:

| 1 |   A      | A1    | 12-DEC-09 | ......
| 1 |   A      | A1    | 12-DEC-09 |........
| 1 |   A      | A1    | 13-DEC-09 |........

I am only get category, brand and its total number with my query.我只能通过查询获得类别、品牌及其总数。

select
    category,
    brand,
    count(*) as total
from
    tbl_category
group by category, brand

But I need the result like above.但我需要上面的结果。

You can use window functions:您可以使用 window 函数:

select c.*
from (select c.*, count(*) over (partition by category, brand) as cnt
      from tbl_category c
     ) c
where cnt > 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM