标签:cno field end 等于 sel sql The from inf
1,insert into table_a select * from table_b
2,insert into table_a(field_a1,field_a2,field_a3) select field_b1,field_b2,field_b3 from table_b
查询:select cno,sum(score) from sc group by cno having sum(score)>100
判断:select cno,sum(score) from sc where sum(score)>100 and cno=#{cno}
3、查出数据前几条最大的
MYSQL:select t.* from (select sno,cno from sc order by cno desc limit 0,3) t order by sno
4、有一张table-t表,里面有三个字段:英语,其中有三条记录分别表示语文70分,数学80分,英语58,请用一条sql语句查询出这三条记录并按以下条件显示出来:
大于或等于80表优秀,大于等于60表及格,小于60表不及格显示格式:
及格 优秀 不及格
select t.yuwen as ‘语文‘,t.shuxue as ‘数学‘,t.english as ‘英语‘ from
(select case when yuwen>=80 then ‘优秀‘ when yuwen>=60 then ‘及格‘ else ‘不及格‘ end yuwen,
case when shuxue>=80 then ‘优秀‘ when shuxue>=60 then ‘及格‘ else ‘不及格‘ end shuxue,
case when english>=80 then ‘优秀‘ when english>=60 then ‘及格‘ else ‘不及格‘ end english
from table_t) t
4、计算及格率
select concat(sum(case when score>60 then 1 else 0 end)/count(*)*100,%) as score from sc
5、 将某列的行内容变成列字段名
变为
select name,sum(case when sub=‘语文‘ then sco end) ‘语文‘,
SUM(case when sub=‘数学‘ then sco end)‘数学‘,SUM(case when sub=‘英语‘ then sco end) ‘英语‘
from score1 GROUP BY name
注:技术本身无底线,随时更新
标签:cno field end 等于 sel sql The from inf
原文地址:https://www.cnblogs.com/jincheng81/p/9038435.html