代码:

select 
    t1.descid,
    IFNULL(t2.cnt,0) as countnew,
    t1.description 
from 
    uosdesc t1 left outer join t2
on 
    t1.descid=t2.descid  
order by 
    countnew desc

说明:

左外连接,左表t1为主表,右表t2为从表。

on后为条件,主表和从表做连接,若从表数据不存在则以NULL填充结果集。

IFNULL判断结果集中字段,若为NULL则以第二个参数0替代之。

 

相关文章:

  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-07-15
  • 2021-11-05
  • 2021-07-29
  • 2021-11-06
  • 2022-01-09
猜你喜欢
  • 2021-07-12
  • 2022-12-23
  • 2021-09-17
  • 2021-10-07
  • 2021-04-10
  • 2022-12-23
  • 2021-09-15
相关资源
相似解决方案