一、数据查询
SMSServer uses three database tables to do:
One for sending the outbound messages.create table smsserver_out (
id int(10) unsigned not null auto_increment,
`type` varchar(1) not null default 'o',
recipient varchar(16) not null,
`text` varchar(1000) not null,
wap_url varchar(100) null default null,
wap_expiry_date datetime null default null,
wap_signal varchar(1) null default null,
create_date datetime not null,
originator varchar(16) not null default ' ',
encoding varchar(1) not null default '7',
status_report int(1) not null default 0,
flash_sms int(1) not null default 0,
src_port int(6) not null default -1,
dst_port int(6) not null default -1,
sent_date datetime null default null,
ref_no varchar(64) null default null,
priority int(5) not null default 0,
`status` varchar(1) not null default 'u',
`errors` int(2) not null default 0,
gateway_id varchar(64) not null default '*',
primary key (id)
)
engine=myisam
row_format=default
auto_increment=33说明:
这是一张短信记录表(mysql),
Id:主键
type:短信类型(’O’为普通短信,’W’为wap短信)
recipient:短信接收者(手机号)
text:短信内容
create_date:短信记录添加时间
status_report:是否需要回执(0为需要回执、1为需要回执)
sent_date:短信发送时间
status:短信状态,"U" : 未发送, "Q" :正在发送, "S" :已发送, "F" : 发送失败,null:未检索.
Errors:错误代码
Gateway_id:串口号1. 统计当天各状态记录总数   select count(status) from smsserver_out;2. 统计1小时内的所有短信记录总数和已发送短信记录总数  select count(status) from smsserver_out where group by ....3. 找出短信记录中,138和139开头的短信接收号码(去除重复号码)4. 统计各串口1小时内已发送短信数量

解决方案 »

  1.   

    1.统计当天各状态记录总数
    select status,count(*) from smsserver_out group by status;2.统计1小时内的所有短信记录总数和已发送短信记录总数
    select count(*) from smsserver_out where UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(sent_date) <=3600;
    select count(*) from smsserver_out where status='S' and UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(sent_date) <=3600;3.找出短信记录中,138和139开头的短信接收号码(去除重复号码)
    select distinct(recipient) from smsserver_out where SUBSTRING(recipient,1,3) in ('138','139');4.统计各串口1小时内已发送短信数量
    select Gateway_id,count(*) from smsserver_out where status='S' and UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(sent_date) <=3600 group by Gateway_id;