开发者

sql count() query for tables

i have two tables

table1 fields

      fid,fname,fage
      a  ,abc  ,20
      b  ,bcv  ,21
      c  ,cyx  ,19

table2 fields

     rcno,fid,status
     1   开发者_C百科,a  ,ok
     2   ,c  ,ok
     3   ,a  ,ok
     4   ,b  ,ok
     5   ,a  ,ok

i want to display rectors like this

     fid from table1 , count(recno) from table 2 and fage from table1         

     fid,count(recno),fage
     a  ,3           ,20
     b  ,2           ,21
     c  ,1           ,19

i try many sql queries but got error

Thanks


You could try

SElECT t1.fid,
       COUNT(t2.fid),
       t1.fage
FROM   Table1 t1 INNER JOIN
       Table2 t2 ON t1.fid = t2.fid
GROUP BY t1.fid, t1.fage
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜