复制代码 代码如下:
CREATE TABLE `result` (
`name` varchar(20) default NULL,
`subject` varchar(20) default NULL,
`score` tinyint(4) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
复制代码 代码如下:
insert into result values
('张三','数学',90),
('张三','语文',50),
('张三','地理',40),
('李四','语文',55),
('李四','政治',45),
('王五','政治',30),
('赵六','语文',100),
('赵六','数学',99),
('赵六','品德',98);
复制代码 代码如下:
select name,sum(score < 60) ,avg(score) from result group by name having sum(score<60) >=2;
复制代码 代码如下:
select name ,count((score<60)!=0) as a,avg(score) from result group by name having a >=2;
新闻热点
疑难解答