表:smsbox_in
spnumber mobile message in_time(datetime)
0755 12011111 T 2005-12-20
0755 12110000 Q 2005-12-10
0755 12011111 Q 2005-12-27
0755 12222222 T 2005-12-01
0755 12110000 T 2005-12-05
1)其中T为注册标识,Q为取消标识,注册和取消都在同一个表中,现在一个问题就是查找某一天取消用户是否是三天前注册的用户,的总人数
主要是这个时间不知道用什么方法来计算
2)求某一天的取消率,就是某一天的取消人数除以当天的注册人数,用一个sql语句写出。
3)还有一个sql乘法就是用sql语句输出注册(message为T)乘以20%的积,
spnumber mobile message in_time(datetime)
0755 12011111 T 2005-12-20
0755 12110000 Q 2005-12-10
0755 12011111 Q 2005-12-27
0755 12222222 T 2005-12-01
0755 12110000 T 2005-12-05
1)其中T为注册标识,Q为取消标识,注册和取消都在同一个表中,现在一个问题就是查找某一天取消用户是否是三天前注册的用户,的总人数
主要是这个时间不知道用什么方法来计算
2)求某一天的取消率,就是某一天的取消人数除以当天的注册人数,用一个sql语句写出。
3)还有一个sql乘法就是用sql语句输出注册(message为T)乘以20%的积,
3)还有一个sql乘法就是用sql语句输出注册(message为T)乘以20%的积,
2) SELECT a/b FROM (SELECT COUNT(*) a FROM smsbox_in WHERE message='Q' AND in_time=?) , (SELECT COUNT(*) b FROM smsbox_in WHERE message='T' AND in_time=?) FROM DUAL;3) SELECT COUNT(*)*0.2 FROM smsbox_in WHERE message='T';这里的 ? 你可以用时间来代替.
上面的2)去掉 FROM DUAL;
select count(a.*) from smsbox_in a,smsbox_in b where a.mobile=b.mobile and a.message='T' and b.message='Q' and datediff(d,b.in_time,a.in_time)>3 (如果含三天则>改为>=)
1)
select
count(*)
from (select * from smsbox_in where message='T') as T,(select * from smsbox_in where message='Q') as Q
where
T.mobile=Q.mobile and (Q.in_time-INTERVAL 3 DAY<T.in_time);2)
select count(Q.*)/count(T.*)*100
from (select * from smsbox_in where message='T' and in_time='你要的时间') as T,(select * from smsbox_in where message='Q' and in_time='你要的时间') as Q;
第三个没看明白,写完每测试,你测试一下看看,基本就是这个意思。
第1问主要使用 DateDiff函数,这是SQL上的已经通过了,这样的数据是显示所有时间的满足你上面的信息:
select count(*) from smsbox_in a,smsbox_in b where a.mobile=b.mobile and a.message='T' and b.message='Q' and datediff(d,a.in_time,b.in_time)>3 (如果含三天则>改为>=)
select a.c/b.d from (select in_time,count(*) as c from smsbox_in where message='T' group by in_time) a,(select in_time,count(*) as d from smsbox_in where message='Q' group by in_time) b where a.in_time=b.in_time可以查出所有时间内的信息,将后续的where条件和子查询的条件预以控制成年,年月,年月日三种形式,可以得到当年取消率,当年月取消率,当年月日取消率.