对于employees表中,给出奇数行的first_name
CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_no`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
myslq写法:
方法一:
select @rowno:=0,a.* from employees a
select @rowno:= @rowno+1 as rowno,t.first_name from (select @rowno:=0,a.* from employees a) t
select tt.rowno,tt.first_name from (select @rowno:= @rowno+1 as rowno,t.first_name from (select @rowno:=0,a.* from employees a) t) tt where mod(tt.rowno,2)<>0;
方法二:
select @rowno:= @rowno+1 as rowno,e.emp_no,e.first_name from employees e,(select @rowno:=0) t
select tt.rowno,tt.first_name from (select @rowno:= @rowno+1 as rowno,e.emp_no,e.first_name from employees e,(select @rowno:=0) t) tt where mod(tt.rowno,2)<>0;