各位大虾: 我有一个一组数据,表结构为:姓名,日期,名称 数据为:
a 2011-12-1 甲
a 2011-12-1 乙
a 2011-12-2 丙
a 2011-12-3 丙
b 2011-12-3 甲我想统计日期 从2011-12-1 到 2011-12-3的一个人数统计,
如果同姓名同个日期人数统计为1,同姓名不同日期人数统计为累加如上面数据 a的人数统计就为 3 b的人数就为1
a 2011-12-1 甲
a 2011-12-1 乙
a 2011-12-2 丙
a 2011-12-3 丙
b 2011-12-3 甲我想统计日期 从2011-12-1 到 2011-12-3的一个人数统计,
如果同姓名同个日期人数统计为1,同姓名不同日期人数统计为累加如上面数据 a的人数统计就为 3 b的人数就为1
解决方案 »
- 求一SQL语句
- Oracle学习
- pro c 问题
- 题目表的设计,超级头疼
- 基础性问题,闲了给解释一下
- 看不懂这段话,请前辈翻译一下
- 请问如何对某一计算出来的结果进行四舍五入呢?例如某两个时间相减之后的结果进行整数的四舍五入
- 在AIX上安装Oracle数据库是提示需要安装IY22854、IY26778等系统补丁,那位大侠知道那里又下载的?
- 为何我的函数一旦加入SQL%FOUND就什么值也不返回 ?????????????????????
- 我没有任何数据库基础,现在需要学习oracle,请各位推荐小弟需要读的书。
- 一个4年的普通DBA给初学者的一些建议
- 高手救命:http://127.0.0.1/isqlplus 打不开
union select 'a','2011-12-1' ,'乙' from dual
union select 'a','2011-12-2' ,'丙' from dual
union select 'a','2011-12-3' ,'丙' from dual
union select 'b','2011-12-3' ,'甲' from dual )
select name,count(*) from (select name,d from t group by name,d ) group by name
select t.name01
,count(distinct t.date01) as Num
from( select name01, date01 from temp1
where date01 between to_date('2011-12-01','yyyy-mm-dd')
and to_date('2011-12-03','yyyy-mm-dd')+1
) t
group by t.name01
结果如下:
select t.name01
,count(distinct t.date01) as Num
from( select name01, date01 from temp1
where date01 between to_date('2011-12-01','yyyy-mm-dd')
and to_date('2011-12-03','yyyy-mm-dd')+1
) t
group by t.name01
NAME01 NUM
a 3
b 1
a 2011-12-1 乙
a 2011-12-2 丙
a 2011-12-3 丙
b 2011-12-3 甲加个distinct子查询去重就可以了。
SELECT COUNT(*) FROM (SELECT DISTINCT id,TRUNC(dt),name FROM TABLE);
create table user_info(
user_id varchar2(10),
date_time varchar2(10),
user_name varchar2(50)
);
统计sql:
select t1.user_id,count(*) from
(
select
t.user_id,t.date_time,count(*)
from user_info t
where to_date(date_time,'yyyy-MM-dd')>=to_date('2011-12-1','yyyy-MM-dd')
and to_date(date_time,'yyyy-MM-dd')<=to_date('2011-12-3','yyyy-MM-dd')
group by t.user_id,t.date_time
) t1
group by t1.user_id
order by t1.user_id
select t1.user_id,count(*) from
(
select
t.user_id,t.date_time,count(*)
from user_info t
where to_date(date_time,'yyyy-MM-dd')>=to_date('2011-12-1','yyyy-MM-dd')
and to_date(date_time,'yyyy-MM-dd')<=to_date('2011-12-3','yyyy-MM-dd')
group by t.user_id,t.date_time
having count(*)<=1
) t1
group by t1.user_id
order by t1.user_id
select 姓名,count(distinct 日期) as num
from tab_name
where 日期>=to_date('2011-12-01','yyyy-mm-dd') and 日期<=to_date('2011-12-03','yyyy-mm-dd')
group by 姓名
count(distinct 名称) 可以了 select 姓名, count(distinct )
from table
where 日期 bewteen 2011-12-1 and 2011-12-3 ( 日期格式自已调整一下)
from table
where 日期 bewteen 2011-12-1 and 2011-12-3 ( 日期格式自已调整一下)
group by 姓名
from (
select
distinct 姓名
,日期
from 表
)