需求
1.将体育测试800米1000米的成绩转换成4‘32‘’的格式
2.统计汇总个人的多项成绩
SQL语句
--10000是自己查询的秒数
SELECT concat(concat(10000 div 3600,'时'),concat(10000 mod 3600 div 60,'分'),concat(10000 mod 60,'秒')) as times
显示:2时64分30秒
--根据实际情况统计
--sum(case when sps.project_id = '007' then sps.result end)相当于10000,是统计的秒数
concat(CONCAT(sum(case when sps.project_id = '007' then sps.result end) mod 3600 div 60,''''),concat(sum(case when sps.project_id = '007' then sps.result end) mod 60,''''''))AS '八百米',
显示:
3.元数据
--多条信息汇总
select
sum(case when sps.project_id = '003' then sps.result end) '肺活量',
sum(case when sps.project_id = '004' then sps.result end) '50米',
sum(case when sps.project_id = '005' then sps.result end) '立定跳远',
sum(case when sps.project_id = '006' then sps.result end) '坐位体前屈',
from tp_total_score ts
left join tp_single_project_score sps on ts.student_id = sps.student_id
显示: