select*fromtypewherepersonid=(selectidfrompersonwhereid='id')查询已知id的play。
- 情感问答
- 答案列表
双表查询:两表查询sql语句[朗读]
selectuf.uid,uf.tel,uf.addressfromuserinfoufwhereuf.uidin(selectu.uidfromuseruwhereu.cityid=1)limit0,10orderbyuf.uid;遍历一遍结果,就可以得到你想要的用户id的数据了。
selecttb.stuname,sum(tb.amount)as总数量,sum(tb.金额)as总金额from(selectta.stuname,ta.amount,ta.amount*book.priceas金额from(selectstudent.stuname,bookorder.bookno,bookorder.amountfromstudentleftjoinbookorderonstudent.stuno=bookorder.stuno)taleftjoinbookonta.bookno=book.bookno)tbgroupbytb.stuname
如果是oracle,以上要求只能通过语句块块实现,不能单一的一个sql展示.语句块中可判断同一个客户超过3条记录,则只显示三条,最后取出5条后终止查询返回结果。
用join关键字即可.举例三表连接:selecttab1.col1,tab1.col2,tab2.col3fromtab1fulljointab2ontab1.col1=tab2.col1。