我怎样才能在sql/oracle中获得不正确的列数? [英] how can i get disninct count of coloumns in sql/oracle ?

查看:72
本文介绍了我怎样才能在sql/oracle中获得不正确的列数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的查询中,我要计算不同的计数

表格:

In my query i want to take the distinct count

Table :

Coloumn 1     Coloumn 2   Coloumn 3
   1             Y           3
   2             Y           3
   3             Y           3
   4             Y           4
   5             Y           4


在这里,我想对第2和第3栏进行计数.
我尝试了


here i want the count of coloumn 2 and 3.
i tried

select count (distInct Coloumn 2 ),count (distinct Coloumn 3 ) from table.


但结果是count ( Coloumn 2 ) = 1count ( Coloumn 3 ) = 2
但期待count ( Coloumn 2 ) = 2和c ount ( Coloumn 3 ) = 2
我该怎么办?
有解决方案吗?

[edit]添加了代码块[/edit]


but the result was count ( Coloumn 2 ) = 1 and count ( Coloumn 3 ) = 2
but am expecting count ( Coloumn 2 ) = 2 and count ( Coloumn 3 ) = 2
how can i do this?
Any solution ?

[edit]Code block added[/edit]

推荐答案

我猜这不可能,因为唯一的区别是考虑独特的价值.由于在第2列中仅存在Y,因此其计数为1.
I guess its not possible since distinct will only consider unique values. Since in column 2 only Y is present it will give the count as 1.


使用:
SELECT  count(T.Coloumn2 ) Column2Count, count(T.Coloumn3 ) Column3Count
FROM (SELECT DISTINCT Coloumn2 ,Coloumn3  FROM table) T

.


这篇关于我怎样才能在sql/oracle中获得不正确的列数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆