Mysql Correlated Query Error -


i trying pair records according 4 conditions, 1 of requires one-level correlated subquery match +/- date range condition.

why old.stdt unknown in subquery's where clause? thank you.

here both data , query:

drop table if exists `sbids`; create table `sbids` (    `bid` int(11) default null,    `sid` int(11) default null,    `ctle` varchar(20) default null,    `stype` char(1) character set utf8 default '',    `sbid` int(8) default null,    `stdt` date default null,    `sedt` date default null  ) engine=innodb default charset=latin1;  insert `sbids` values     ( 11228,  8367, 'rrr', 'a', 11495, '2012-02-01', '2014-01-01'),    ( 11228,  8367, 'rrr', 'a',  8182, '2014-03-01', '2015-02-01'),    ( 11228,  8367, 'ccc', 'b', 29256, '2014-09-01', '2015-08-31'),    ( 11228, 18030, 'rrr', 'a', 23319, '2013-01-01', '2013-11-01'),    ( 11228, 18030, 'ccc', 'a', 25304, '2014-01-01', '2014-11-01'),    ( 11228, 18030, 'ccc', 'a', 25304, '2015-01-01', '2015-11-01');  drop table if exists prd; create table prd select       old.bid,        old.sid,       old.sbid old_sbid,       old.ctle old_ctle,        old.stype old_stype,       old.stdt old_stdt,        old.exdt old_exdt,       can.sbid can_sbid,        can.ctle can_ctle,        can.stype can_stype,       can.stdt can_stdt,        can.exdt can_exdt           sbids old           inner join ( select                              innert.bid,                              innert.sid,                              innert.ctle,                             min(innert.stdt) stdt                                                       sbids innert                                                        abs(datediff( old.stdt , innert.exdt )) <= 65                          group                              innert.bid,                              innert.sid,                              innert.ctle ) can              on old.bid  = can.bid              , old.sid  = can.sid              , old.ctle = can.ctle 


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -