2018-08-03左连接
select A.operator,a.qty,case when s.username is null then A.operator else s.username end username,
CASE WHEN b.qty IS NULL THEN 0 ELSE B.QTY END Qc_Qty,
case when b.qty is null then '0.00%' else
TO_CHAR(round(B.qty/A.qty* 100,2), 'FM990.00')||'%' end rate,
C.QTY QTYC
,CASE WHEN B.QTY IS NULL THEN '0.00%' ELSE TO_CHAR(ROUND(B.QTY/C.QTY* 100,2),'FM990.00')||'%' END rate2
from
(select br.operator,F.LOT_ID,count(*) qty from bl_record br
INNER JOIN (select bl_id,LOT_ID from oqc_bl_check where lot_id='20180801143533.353955') F ON F.BL_ID = BR.BL_ID
and ws_id='260'
and br.trans_type = 'A'
group by br.operator,F.LOT_ID
)A
left join
(select
br.operator,F.LOT_ID,count(*) qty from bl_record br
INNER JOIN (select LOT_ID,bl_id from oqc_bl_check where lot_id='20180801143533.353955') F ON F.BL_ID = BR.BL_ID
and ws_id='260'
and br.trans_type = 'B'
group by br.operator,F.LOT_ID
)B ON A.operator = B.operator AND A.LOT_ID = B.LOT_ID
LEFT JOIN
(select F.LOT_ID,count(*) qty from bl_record br
INNER JOIN (select bl_id,lot_id from oqc_bl_check where lot_id='20180801143533.353955') F ON F.bl_id=BR.BL_ID
and ws_id='260'
and br.trans_type = 'A'
group by F.LOT_ID
)C ON A.LOT_ID = C.LOT_ID
left join sysuser S on a.operator=s.usercode
今天主要学习了oracle的左连接.知道今天遇到了才理解了左连接的意思.简单的来说,无论是何种连接就是把需要连接的两张表连接合并成一张表,而工作意义中,则是为了把来自两个表的结果合并为来自一个表的结果.(因为C#的listView的一个item只能绑定一个数据源)
因为客户的需求,想把两笔没有相同操作人的数据整理至同一个listview中,并且两边操作人的数量也未必相同.一开始的想法是,是不是有某种方法能把没有关联的两张表并联在一起,结果是否定的.于是做成了两个listview.过了一会想起前一段时间使用的创建序列号的语句row_number() over (order by a.operator)nbr
于是想到,可以把左右两张表加上序列号.根据序列号把两张表串联到一起
其中,用户想要的结果需要用到抽检总数与NG总数,惯性思维下,会把总数的结果也放在表中做连接.但是使用count又需要group by做条件,所以有时过程会比较繁琐.于是想到可以直接把select count(*)from table作为一个总数放到select中做结果