现有如下4张表:(用户管理表,终端表,会员表,电子地图表)
   user_manage           terminal_info                client_info        elec_info
userId clientId    termId clientId tName elecId    clientId  cName     elecId   eName
 1000   1001         1      1001    tA     1         1001      cA        1        eA
 1000   1003         2      1001    tB     1         1002      cB        2        eB 
 1000   1005         3      1002    tC     3         1003      cC        3        eC  
 1001   1002         4      1003    tD     2         1004      cD        4        eD  
 1001   1004         5      1004    tE     4         1005      cE        5        eE
                     6      1002    tF     5           .        .        6        eF   
                     7      1002    tG     1           .        . 
                     8      1005    tH     6  条件:根据(userId) 查询出对应的clientId,在根据clientId对terminal_info表进行查询,求出数量count值
希望得出以下结果:  
条件如果: userId=1001                                 userId=1000
clientId  cName  count                        clientId  cName  count
 1002      cB     3                              1001     cA     2    
 1004      cD     1                              1003     cC     1
                                                 1005     cE     1在线等....着急...大侠多帮忙....

解决方案 »

  1.   

    假如看不清,请copy至文本文件中查看
      

  2.   

    select a.clientId,b.cName ,count(a.clientId) `count` from terminal_info a, client_info b
    where a.clientId = b.clientId and a.clientId in 
    (select clientId from user_manage where userId = 1001)
    group by a.clientId ;
      

  3.   


    所有的userId 对应的结果:
    select a.clientId,b.cName ,count(a.clientId)from terminal_info a, client_info b
    where a.clientId = b.clientId and a.clientId in 
    (select clientId from user_manage)
    group by a.clientId ;
      

  4.   

    query result(5 records)
    clientId cName count(a.clientId) 
    1001 cA 2 
    1002 cB 3 
    1003 cC 1 
    1004 cD 1 
    1005 cE 1