面试总结 不断ing

面试总结

2011/9/2

1 将两个表的结果集联合起来

答案:采用union 或者union all 区别:union all是将结果集拼合在一起,union是将union all之后的结果再进行医次distinct ,去掉重复后的结果

2 有两个表,student 学生表 score 成绩表 ,要求显示学生姓名和学生总成绩

本题考点:group by 表连接

select A,count(B) 数量 from table group by A

这样的结果就是

A  数量

1   3

group by 有一个原则,就是 select 后面的所有列中,没有使用聚合函数的列,必须出现在 group by 后面

完整示例:

select a.name aname ,sum(b.score) from a ,b where a.id=b.id group by a.name

猜你喜欢

转载自helloworlda.iteye.com/blog/1164595
ing
今日推荐