用户表---   user  
   
  uid       username  
  1           user1  
  2           user2  
  3           user3  
  .........  
   
  数据表1---     table1  
   
  id     useranme     a     b     c     d  
  1         user1         1     1     1     1  
  2         user1         1     1     1     1  
  3         user2         1     1     1     1  
  4         user3         1     1     1     1  
  5         user2         1     1     1     1  
  6         user3         1     1     1     1  
   
  数据表2   ----table2  
  id     username     suma     sumb     sumc     sumd  

  select   username,suma=sum(a),sumb=sum(b),subc=sum(c),subd=sum(d)   from   table1   aa  
  where   exists(   select   *   from   user1   where   username=aa.username)  
  group   by   username 

   
  select   u.username,suma=sum(a),sumb=sum(b),subc=sum(c),subd=sum(d)  
  from ((select   *   from   user1) as u inner join  table1 on  u.username=table1.username)
   group   by   u.username  

相关文章:

  • 2023-04-07
  • 2022-12-23
  • 2022-02-24
  • 2021-10-24
  • 2021-12-18
  • 2021-06-12
  • 2021-05-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2023-03-18
  • 2021-10-31
  • 2021-10-15
  • 2022-12-23
相关资源
相似解决方案