日期:2014-05-17  浏览次数:20430 次

sql 总计记录数与明细查询记录数不一致
select b.inv_code 材料编码,c.inv_name 材料名称,c.inv_model 材料规格,u.unit_name 单位,b.price 成本价,b.amount 数量,b.sell_price 零售单价,v.ven_name 生产厂家,c.cert_code 证件号, a.year_month 出库日期,a.iow_no 出库单号,a.conf_date 出库确认日期,dept.dept_name  领用科室,d.store_name 移出仓库 
from mate_whr_detail b 
inner join mate_whr_main a on a.iow_id=b.iow_id
inner join mate_inv_dict c on b.inv_code=c.inv_code
left join sys_dept dept on a.dept_code=dept.dept_code
left join sys_store_dict d1 on a.exch_store_code = d1.store_code
left join sys_store_dict d on a.store_code = d.store_code
left join sys_vendor_dict v on c.cus_code = v.ven_code
left join sys_unit u on c.unit_code = u.unit_code
where  a.bus_type_code =14 
and a.make_date>='2012-01-01' and a.make_date<='2012-12-31'  
and is_in_out=0   
and a.exch_store_code ='05' 
group by a.year_month ,a.iow_no,b.inv_code,c.inv_name,c.inv_model,c.cert_code,u.unit_name,b.price,b.amount,b.sell_price,v.ven_name,a.year_month,a.iow_no,dept.dept_name ,d.store_name,a.conf_date
order by a.iow_no



select count(a.iow_id) as 条数
from mate_whr_detail b 
inner join mate_whr_main a on a.iow_id=b.iow_id
inner join mate_inv_dict c on b.inv_code=c.inv_code
left join sys_dept dept on a.dept_code=dept.dept_code
left join sys_store_dict d1 on a.exch_store_code = d1.store_code
left join sys_store_dict d on a.store_code = d.store_code
left join sys_vendor_dict v on c.cus_code = v.ven_code
left join sys_unit u on c.unit_code = u.unit_code
where  a.bus_type_code =14 
and a.make_date>='2012-01-01' and a.make_date<='2012-12-31' 
and is_in_out=0  
and a.exch_store_code='05'

------解决方案--------------------
关联查询中你用到了left join