sql - Mysql: How to get a result for each day in between an start and an end date from a table that contains also a start and an end date? -
i have start date , end date. each day between start , end date result, if there no results within stats table.
the best suggestion solve stored procedure creates temporary table each date (day) create join.
begin declare d datetime; create temporary table joindates (d date not null); set d = fkstartdate; while d <= fkenddate insert joindates (d) values (d); set d = date_add(d, interval 1 day); end while; select * `joindates` tempt left join `radacct` stats on stats.acctstarttime <= tempt.d , (stats.acctstoptime >= tempt.d or stats.acctstoptime null) , calledstationid = calledstationid order tempt.d asc; drop temporary table joindates; end
the join not finalized (just testing). see, join perfect if "radacct" table use 1 date col. create join using = operator on.
now "radacct" using acctstarttime , acctstoptime there entries (i can not modify table, given radius server) both datetime types.
so in query need entries between start , stop date acctstarttime has started in past or within time period. , acctstoptime within time period, after time period or null (active session).
the problem join solution: slow hell may have faster query ideas please?
thanks
appendix1: important result each entry on each day matches period of days, if acctstarttime acctstoptime goes on multiple days. users online.
appendix2: requested, full table structure of "radacct" – accounting table of freeradius mysql module …
create table `radacct` ( `radacctid` bigint(21) not null auto_increment, `acctsessionid` varchar(64) not null default '', `acctuniqueid` varchar(32) not null default '', `username` varchar(64) not null default '', `groupname` varchar(64) not null default '', `realm` varchar(64) default '', `nasipaddress` varchar(15) not null default '', `nasportid` varchar(15) default null, `nasporttype` varchar(32) default null, `acctstarttime` datetime default null, `acctstoptime` datetime default null, `acctsessiontime` int(12) unsigned default null, `acctauthentic` varchar(32) default null, `connectinfo_start` varchar(50) default null, `connectinfo_stop` varchar(50) default null, `acctinputoctets` bigint(20) default null, `acctoutputoctets` bigint(20) default null, `calledstationid` varchar(50) not null default '', `callingstationid` varchar(50) not null default '', `acctterminatecause` varchar(32) not null default '', `servicetype` varchar(32) default null, `framedprotocol` varchar(32) default null, `framedipaddress` varchar(15) not null default '', `acctstartdelay` int(12) unsigned default null, `acctstopdelay` int(12) unsigned default null, `xascendsessionsvrkey` varchar(10) default null, primary key (`radacctid`), unique key `acctuniqueid` (`acctuniqueid`), key `username` (`username`), key `framedipaddress` (`framedipaddress`), key `acctsessionid` (`acctsessionid`), key `acctsessiontime` (`acctsessiontime`), key `acctstarttime` (`acctstarttime`), key `acctstoptime` (`acctstoptime`), key `nasipaddress` (`nasipaddress`) ) engine=innodb auto_increment=2041894 default charset=latin1
Comments
Post a Comment