SQL面试集

1.两张表,店铺表(s_id,sname,loc)和订单表(o_id,oname,money,s_id),店铺和订单是一对多关系,查询订单数大于等于20的店铺.

答:select s.s_id,s.sname from shop s inner join ordertable o on s.s_id = o.s_id group by s.s_id,s.sname having count(o.o_id)>=20;

2.给两张表t1和t2,t1有列id,name,t2有列id,name,log,t1表中id=10的name更新了,怎么把t1中id为10的那行name值更新到t2表中id为10的name中?(t1和t2的id有关联)

答:update t1,t2 set t2.name=t1.name where t1.id=t2.id and t1.id=10;

猜你喜欢

转载自www.cnblogs.com/hexiaoming/p/9107413.html