mysql - Counting a row within an overall listing of data -


this question has answer here:

i have table contains matches particular competition.

when select matchidauto 4050, need know match 15 of total 29 matches in competition.

i can determine there 29 matches simple select count(*) match2 competitionidauto = 669

does know of way of determining without needing loop through example 4050 match 15?

     --     -- table structure table `match2`     --      create table if not exists `match2` (     `matchidauto` int(10) not null auto_increment,     `competitionidauto` int(10) not null default '0',     `teamhome` varchar(100) not null default '0',     `teamaway` varchar(100) not null default '0',     `matchdate` date not null default '0000-00-00',     `matchtime` time not null default '00:00:00',     `matchstarttime` datetime not null default '0000-00-00 00:00:00',     `venueidauto` int(10) not null default '0',     `gameended` int(1) not null default '0',     `predictionsgameended` int(1) not null default '0',     `result` varchar(50) not null default '',     `resulturl` varchar(100) not null default '',     `datecreated` date not null default '0000-00-00',     `datecreatedtimestamp` int(10) not null default '0',     `datemodified` date not null default '0000-00-00',     `usercreated` varchar(50) not null default '',     `disablethismatch` int(1) not null default '0',     `allocatedto` varchar(25) not null,     `matchupdated` tinyint(1) not null default '0',     primary key (`matchidauto`)     ) engine=myisam  default charset=latin1 auto_increment=4234 ;      --     -- dumping data table `match2`     --     insert `match2` (`matchidauto`, `competitionidauto`, `teamhome`, `teamaway`, `matchdate`, `matchtime`, `matchstarttime`, `venueidauto`, `gameended`, `predictionsgameended`, `result`, `resulturl`, `datecreated`, `datecreatedtimestamp`, `datemodified`, `usercreated`, `disablethismatch`, `allocatedto`, `matchupdated`) values    (4036, 669, 'brisbane heat women', 'hobart hurricanes women', '2016-01-01', '03:40:00', '2015-12-31 21:40:00', 7, 0, 0, '', '', '2015-11-13', 1447473564, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4037, 669, 'perth scorchers women', 'adelaide strikers women', '2016-01-01', '04:10:00', '2015-12-31 22:10:00', 3, 0, 0, '', '', '2015-11-13', 1447474751, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4038, 669, 'sydney thunder women', 'brisbane heat women', '2016-01-02', '01:00:00', '2016-01-01 19:00:00', 316, 0, 0, '', '', '2015-11-13', 1447474966, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4039, 669, 'melbourne stars women', 'melbourne renegades women', '2016-01-02', '02:40:00', '2016-01-01 20:40:00', 8, 0, 0, '', '', '2015-11-13', 1447475064, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4040, 669, 'sydney thunder women', 'hobart hurricanes women', '2016-01-02', '07:00:00', '2016-01-02 01:00:00', 7, 0, 0, '', '', '2015-11-13', 1447475178, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4041, 669, 'hobart hurricanes women', 'brisbane heat women', '2016-01-03', '00:00:01', '2016-01-02 18:00:01', 316, 0, 0, '', '', '2015-11-13', 1447475258, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4042, 669, 'melbourne renegades women', 'melbourne stars women', '2016-01-03', '03:30:00', '2016-01-02 21:30:00', 8, 0, 0, '', '', '2015-11-13', 1447475350, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4043, 669, 'hobart hurricanes women', 'sydney thunder women', '2016-01-03', '04:00:00', '2016-01-02 22:00:00', 316, 0, 0, '', '', '2015-11-13', 1447475429, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4044, 669, 'adelaide strikers women', 'melbourne stars women', '2016-01-07', '23:00:00', '2016-01-07 17:00:00', 310, 0, 0, '', '', '2015-11-13', 1447475525, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4045, 669, 'melbourne renegades women', 'sydney sixers women', '2016-01-08', '03:30:00', '2016-01-07 21:30:00', 310, 0, 0, '', '', '2015-11-13', 1447475613, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4046, 669, 'sydney sixers women', 'adelaide strikers women', '2016-01-08', '23:00:00', '2016-01-08 17:00:00', 310, 0, 0, '', '', '2015-11-13', 1447475711, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4047, 669, 'adelaide strikers women', 'sydney sixers women', '2016-01-09', '03:30:00', '2016-01-08 21:30:00', 310, 0, 0, '', '', '2015-11-13', 1447475802, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4048, 669, 'melbourne renegades women', 'sydney thunder women', '2016-01-09', '03:40:00', '2016-01-08 21:40:00', 317, 0, 0, '', '', '2015-11-13', 1447476726, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4049, 669, 'melbourne stars women', 'adelaide strikers women', '2016-01-09', '23:00:00', '2016-01-09 17:00:00', 310, 0, 0, '', '', '2015-11-13', 1447476819, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4050, 669, 'sydney sixers women', 'melbourne renegades women', '2016-01-10', '03:30:00', '2016-01-09 21:30:00', 310, 0, 0, '', '', '2015-11-13', 1447476917, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4051, 669, 'melbourne stars women', 'sydney thunder women', '2016-01-15', '03:30:00', '2016-01-14 21:30:00', 318, 0, 0, '', '', '2015-11-13', 1447477125, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4052, 669, 'hobart hurricanes women', 'sydney sixers women', '2016-01-15', '03:30:00', '2016-01-14 21:30:00', 319, 0, 0, '', '', '2015-11-13', 1447477325, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4053, 669, 'adelaide strikers women', 'melbourne renegades women', '2016-01-15', '03:30:00', '2016-01-14 21:30:00', 320, 0, 0, '', '', '2015-11-13', 1447477775, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4054, 669, 'adelaide strikers women', 'brisbane heat women', '2016-01-15', '23:30:00', '2016-01-15 17:30:00', 320, 0, 0, '', '', '2015-11-13', 1447477920, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4055, 669, 'sydney sixers women', 'sydney thunder women', '2016-01-16', '02:40:00', '2016-01-15 20:40:00', 10, 0, 0, '', '', '2015-11-13', 1447478942, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4056, 669, 'hobart hurricanes women', 'melbourne stars women', '2016-01-16', '03:30:00', '2016-01-15 21:30:00', 315, 0, 0, '', '', '2015-11-13', 1447479213, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4057, 669, 'perth scorchers women', 'melbourne renegades women', '2016-01-16', '04:10:00', '2016-01-15 22:10:00', 320, 0, 0, '', '', '2015-11-13', 1447479324, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4058, 669, 'sydney thunder women', 'melbourne stars women', '2016-01-16', '23:00:00', '2016-01-16 17:00:00', 321, 0, 0, '', '', '2015-11-13', 1447479527, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4059, 669, 'sydney sixers women', 'hobart hurricanes women', '2016-01-16', '23:00:00', '2016-01-16 17:00:00', 322, 0, 0, '', '', '2015-11-13', 1447479733, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4060, 669, 'melbourne renegades women', 'adelaide strikers women', '2016-01-16', '23:30:00', '2016-01-16 17:30:00', 320, 0, 0, '', '', '2015-11-13', 1447479830, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4061, 669, 'melbourne renegades women', 'perth scorchers women', '2016-01-17', '04:10:00', '2016-01-16 22:10:00', 320, 0, 0, '', '', '2015-11-13', 1447479954, '2015-11-13', 'jerry', 0, 'jerry', 0),    (4064, 669, 'semi final', 'semi final', '2016-01-21', '00:00:01', '2016-01-20 18:00:01', 323, 0, 0, '', '', '2015-11-14', 1447523483, '2015-11-14', 'jerry', 0, 'jerry', 0),    (4065, 669, 'semi final', 'semi final', '2016-01-22', '00:00:01', '2016-01-21 18:00:01', 323, 0, 0, '', '', '2015-11-14', 1447523558, '2015-11-14', 'jerry', 0, 'jerry', 0),    (4066, 669, 'final', 'final', '2016-01-24', '00:00:01', '2016-01-23 18:00:01', 323, 0, 0, '', '', '2015-11-14', 1447523614, '2015-11-14', 'jerry', 0, 'jerry', 0); 

i assume matches inserted in ascending order (by date) first match hast lowest matchidauto.

so try this

select m.matchidauto, count( * ) row_number match2 m join match2 m2 on m.matchidauto >= m2.matchidauto m.matchidauto = 4050 group m.matchidauto 

output

+-------------+------------+ | matchidauto | row_number | +-------------+------------+ |        4050 |         15 | +-------------+------------+ 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -