帮忙看下mysql的动态语句,不是很熟悉,该怎么处理

帮忙看下mysql的动态语句,不是很熟悉,该怎么处理

帮忙看下mysql的动态语句,不是很熟悉

MYSQL

如何动态(即科目数不确定)的查询出表中的成绩总分,平均分:

会用固定语句查出某些科目的:

select Number,sum(case subject when ‘数学 ‘ then Sources  

  end) as ‘数学 ‘,

  sum(case subject when ‘英语 ‘ then Sources 

  end) as ‘英语 ‘,

  sum(case subject when ‘语文 ‘ then Sources end) as ‘语文 ‘,SUM(Sources) as 总分, AVG(Sources) as 平均分

from test

group by Number;

如果科目不确定的时候该怎么用动态语句查询,高手指点下;

表示这样子的:

ID number subject sources

1 1 语文 60

2 1 数学 70

3 1 英语 75

4 2 语文 55

5 2 数学 53

6 2 英语 75

7 3 语文 80

8 4 数学 0

9 5 英语 91

最后查出的结果是这样子的

number 数学 英语 语文 总分 平均分

1 70 75 60 205 68.3333

2 53 75 55 183 61

3 80 80 80

4 0 0 0

5 91 91 91

mysql用动态语句怎么实现?

高手指点下mysql的动态语句,新手学习中




http://blog.csdn.net/acmain_chm/article/details/4283943

 MySQL交叉表

在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c…

帮忙看下mysql的动态语句,不是很熟悉,该怎么处理

相关文章:

你感兴趣的文章:

标签云: