两道sql面试题:
1. 数据库表A的数据如下:
year quarter
2001 1
2001 2
2001 3
2001 4
2002 1
2002 2
2002 3
2002 4
写一条SQL语句,使得打印结果为:
year quarter1 quarter2 quarter3 quarter4
2001 1 2 3 4
2002 1 2 3 4
------------------------------------------------------------------
2:
有两张关联的表A、B
A: id acount pay_id B: pay_id B_acount
1 100 1 1 0
2 200 2 2 0
3 200 1
要求,更新表B,使得B_acount的值等于表A中对应的pay_id的所有acount之和。打印如下:
B: pay_id B_acount
1 300
2 200
转载于:https://www.cnblogs.com/gates/p/3549119.html