boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 问一个数据库的题
相关主题
[Mysql] how to return NULL count in group by query
Help! proc sql;cout not null value.
请教data mining 的问题,在线等,谢谢!
sas问题
我也来请教一个SAS问题
SAS Proc SQL count问题
给duplicate加flag
[求助]count coverage days
proc sql count(distinct XX) and count (unique xx)
Oracle query 求助
相关话题的讨论汇总
话题: distinct话题: null话题: 08话题: 数据库话题: 00
进入Statistics版参与讨论
1 (共1页)
f**********n
发帖数: 828
1
假设有这个一个table:
state | phone_number | call_time | answer_time
一个entry可以是下面这个样子
WA | 123-456-7890 | 2013-07-08 08:00:00 | NULL
或者
WA | 123-456-7890 | 2013-07-08 08:00:00 | 2013-07-08 08:13:00
对于同一个电话号码,可能有好几个entry,因为call好几次。。
要求找出对于每一个state来说,所有(distinct)电话号码的总数,所有answer_time
至少有一个不是null的(distinct)电话号码总数。
好像不是一个难题。。。可是我越来越晕了。。。
谢谢!!!!
a******n
发帖数: 11246
2
写两个query好了,第一步把NULL的都扔掉
create table temp as
sel * from table where answer_time is not null;
再计算每个州的distinct电话总数
sel state, count(distinct phone_number) from temp group by 1;

time

【在 f**********n 的大作中提到】
: 假设有这个一个table:
: state | phone_number | call_time | answer_time
: 一个entry可以是下面这个样子
: WA | 123-456-7890 | 2013-07-08 08:00:00 | NULL
: 或者
: WA | 123-456-7890 | 2013-07-08 08:00:00 | 2013-07-08 08:13:00
: 对于同一个电话号码,可能有好几个entry,因为call好几次。。
: 要求找出对于每一个state来说,所有(distinct)电话号码的总数,所有answer_time
: 至少有一个不是null的(distinct)电话号码总数。
: 好像不是一个难题。。。可是我越来越晕了。。。

f**********n
发帖数: 828
3
不是哦,要求只用一个query
然后,我可能没有表达清楚。
有些电话号码可能是没有被answer过的,这些也要count
然后,group by state

【在 a******n 的大作中提到】
: 写两个query好了,第一步把NULL的都扔掉
: create table temp as
: sel * from table where answer_time is not null;
: 再计算每个州的distinct电话总数
: sel state, count(distinct phone_number) from temp group by 1;
:
: time

l****u
发帖数: 529
4
Select distinct state, count(distinct telenum) as totnum, count( distinct (
case when answer ne 'null' then telenum else . end)) as ansnum
From your data
Group by state;
f**********n
发帖数: 828
5
原来count里面可以用case when then!
谢谢啦!!

(

【在 l****u 的大作中提到】
: Select distinct state, count(distinct telenum) as totnum, count( distinct (
: case when answer ne 'null' then telenum else . end)) as ansnum
: From your data
: Group by state;

1 (共1页)
进入Statistics版参与讨论
相关主题
Oracle query 求助
请大侠指教,在R 里面run query的问题。
在实际工作MySQL query optimization的问题
Apple 电话面试 面经
请教一个简单的SQL问题
[合集] 说一个proc sort的很简单却总有人错的问题
如何删除重复的OBS?
请教proc sql
一个类似 coupon collector 的问题
请教一个SAS问题,烦请大家帮我看看
相关话题的讨论汇总
话题: distinct话题: null话题: 08话题: 数据库话题: 00