select a.销售企业名, (select count(*) from 表B where datediff(day,出货日期,getdate())=0 and 企业名=a.企业名 )as 发票数,企业规模级别 from 表B a,表A where a.销售企业名=表A.销售企业名 order by 销售产品数
try: select B.*,A.企业规模级别 from 表A left join (select 销售企业名,count(*) 发票数 from 表B where datediff(day,出货日期,getdate())=0 group by 企业名) B on A.企业名=B.销售企业名 order by 发票数
ON 的条件可以是多的吗? 比如 on (A.企业名=B.销售企业名 and .... and ....)
你如果是用的scmail81的方法,因為表A left join 表B 所以當某個企業今天沒有銷售情況而它又存在於表A中則會 會出現"发票数為NULL"的情況on的條件可以是多個的
(select count(*) from 表B
where datediff(day,出货日期,getdate())=0 and 企业名=a.企业名
)as 发票数,企业规模级别
from 表B a,表A
where a.销售企业名=表A.销售企业名
order by 销售产品数
select B.*,A.企业规模级别
from 表A left join (select 销售企业名,count(*) 发票数
from 表B
where datediff(day,出货日期,getdate())=0 group by 企业名) B on A.企业名=B.销售企业名
order by 发票数
所以當某個企業今天沒有銷售情況而它又存在於表A中則會
會出現"发票数為NULL"的情況on的條件可以是多個的