![在此处输入图像说明] [1]我正在处理数据库并对有条款进行了一些查询。
我有一张桌子
sales
(
id number(5) primary key,
amt number(10),
house_no varchar2 (10),
city varchar2 (10)
)
我的问题是,我想找到每个条目中city
和house_no
相同的特定sales_id及其计数。
我试图解决它但尚未达到目的。我正在使用oracle 10g
。
答案 0 :(得分:1)
SELECT count(*), s2.house_no, s2.city FROM sales s1
INNER JOIN sales s2 ON s1.id = s2.id
GROUP BY s2.city, s2.house_no
HAVING count(*) > 1;
将输出显示为
| COUNT(*) | HOUSE_NO | CITY |
|----------|----------|--------|
| 2 | 102 | Pune |
| 3 | 540 | Sangli |
Reference用于多列的GROUP BY子句
答案 1 :(得分:0)
试试这个:
select id, cnt
from (select city, house_no, count(*) as cnt
from sales t
group by city, house_no) t,
sales c
where t.city = c.city
and t.house_no = c.house_no
Prathamesh 07 : 你好我的问题的进一步描述是....
<强>解决方案:强>
select count(*) as cnt, city, house_no
from sales t
group by city, house_no
having count(*)>1