例如,一个发送表,字段有
username 用户名称
mobile 手机号码
现在我想统计某个用户在某天的短信发送总量,和其中移动、联通、小灵通分别的发送量,该用户移动+联通+小灵通=发送总量,请问在一条语句中如何实现?
username 用户名称
mobile 手机号码
现在我想统计某个用户在某天的短信发送总量,和其中移动、联通、小灵通分别的发送量,该用户移动+联通+小灵通=发送总量,请问在一条语句中如何实现?
try:select t.username, a.yd,b.lt,c.xlt,(a.yd+b.lt+c.xlt)total from table1 t inner join(
select count(username)yd ,username from table1 where username='xxx' and datetime='2007-12-12' and substring(mobile,1,3) in ('135','136','137','138','139'))a on t.username=a.username
inner join(
select count(username)lt ,username from table1 where username='xxx' and datetime='2007-12-12' and substring(mobile,1,3) in ('130','131'))b on t.username=b.username
inner join (
select count(username)xlt ,username from table1 where username='xxx' and datetime='2007-12-12' and substring(mobile,1,3) not in ('130','131','135','136','137','138','139'))c
on t.username=c.username;