接上帖,格式化了一下, markdown 还是有点问题,有没有优化的建议

2018-01-16 15:20:48 +08:00
 poupoo

select * from (select 'aaa' as batch_no, sum(case when t.result = 0 then 1 else 0 end) final_ng_cnt, count(distinct t.code) as final_total from (select a.item, a.code, a.result, a.datetime, a. recordid, dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '0000000') desc) as final_flag from fruit_table_a a inner join fruit_table_b b on a. recordid = b.productid where instr(a.code, '000000000000') = 0 and instr(a.code, '9999999') = 0 and instr(nvl(b.batch_no, '@@@'), '@@@') = 0 and b.batch_no = 'aaa') t where t.final_flag = 1) u left join (select 'aaa' as batch_no, sum(case when c.first_rs = 1 then 1 else 0 end) color_cnt, count(c.code) as color_total

         from (select b.batch_no,
                      a.item,
                      a.code,
                      a.result as first_rs,
                      a.datetime,
                      dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '00000000')) as first_flag
                 from fruit_table_a a
                inner join fruit_table_b b on a. recordid = b.productid

                where instr(a.code, '000000000000') = 0
                  and instr(a.code, '9999999') = 0
                  and instr(a.item, '0019') > 0
                  and b.batch_no = 'aaa') c
        where c.first_flag = 1) v on u.batch_no = v.batch_no
left join (select 'aaa' as batch_no,
              sum(case
                    when instr(g.result, '0') = 0 then
                     1
                    else
                     0
                  end) weight_pass_cnt,
              count(g.code) as weight_total
         from (select k.code,
                      wm_concat(k.item) rank,
                      wm_concat(k.result) as result
                 from (select distinct c. recordid,
                                       c.batch_no,
                                       c.line_num,
                                       c.station_id,
                                       c.thread_id,
                                       c.item,
                                       c.code,
                                       c.result,
                                       c.datetime,
                                       c.first_flag
                         from (select a. recordid,
                                      b.batch_no,
                                      a.line_num,
                                      a.station_id,
                                      a.thread_id,
                                      a.item,
                                      a.code,
                                      a.result,
                                      a.datetime,
                                      dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '0000000')) as first_flag
                                 from fruit_table_a a
                                inner join fruit_table_b b on a.
                                recordid =
                                                              b.productid

                                where instr(a.code, '000000000000') = 0
                                  and instr(a.code, '9999999') = 0
                                  and instr(a.item, '0823') > 0
                                  and b.batch_no = 'aaa'
                               union all
                               select a. recordid,
                                      b.batch_no,
                                      a.line_num,
                                      a.station_id,
                                      a.thread_id,
                                      a.item,
                                      a.code,
                                      a.result,
                                      a.datetime,
                                      dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '0000000')) as first_flag
                                 from fruit_table_a a
                                inner join fruit_table_b b on a.
                                recordid =
                                                              b.productid

                                where instr(a.code, '000000000000') = 0
                                  and instr(a.code, '9999999') = 0
                                  and instr(a.item, '0923') > 0
                                  and b.batch_no = 'aaa'
                               union all
                               select a. recordid,
                                      b.batch_no,
                                      a.line_num,
                                      a.station_id,
                                      a.thread_id,
                                      a.item,
                                      a.code,
                                      a.result,
                                      a.datetime,
                                      dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '0000000')) as first_flag
                                 from fruit_table_a a
                                inner join fruit_table_b b on a.
                                recordid =
                                                              b.productid

                                where instr(a.code, '000000000000') = 0
                                  and instr(a.code, '9999999') = 0
                                  and instr(a.item, '1023') > 0
                                  and b.batch_no = 'aaa') c) k
                group by k.code) g
        where instr(g.rank, '0823') > 0
          and instr(g.rank, '0923') > 0
          and instr(g.rank, '1023') > 0) y on u.batch_no = y.batch_no
left join (select 'aaa' as batch_no,
              sum(count(c.code)) as residual_total,
              sum(sum(case
                        when c.final_flag = 1 and c.result = 0 then
                         1
                        else
                         0
                      end)) last_ng_cnt
         from (select b.batch_no,
                      a.line_num,
                      a.station_id,
                      a.thread_id,
                      a.item,
                      a.code,
                      a.result,
                      a.datetime,
                      dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '0000000') desc) as final_flag
                 from fruit_table_a a
                inner join fruit_table_b b on a. recordid = b.productid

                where instr(a.code, '000000000000') = 0
                  and instr(a.code, '9999999') = 0
                  and instr(a.item, '0823') = 0
                  and instr(a.item, '0923') = 0
                  and instr(a.item, '1023') = 0
                  and instr(a.item, '23') > 0
                  and b.batch_no = 'aaa') c
        group by c.code) z on u.batch_no = z.batch_no
left join (select 'aaa' as batch_no,
              sum(case
                    when g.first_rs = 1 and g.first_flag = 1 then
                     1
                    else
                     0
                  end) package_pass_cnt,
              count(distinct g.code) as package_total

         from (select 'aaa' as batch_no,
                      a.item,
                      a.code,
                      a.result as first_rs,
                      a.datetime,
                      dense_rank() over(partition by a.code, a.fruit_name, a.item order by nvl(a. recordid, '00000000')) as first_flag
                 from fruit_table_a a
                inner join fruit_table_b b on a. recordid = b.productid

                where instr(a.code, '000000000000') = 0
                  and instr(a.code, '9999999') = 0
                  and b.batch_no = 'aaa'
                  and instr(a.item, '0020') > 0) g) p on u.batch_no =
                                                         p.batch_no
972 次点击
所在节点    问与答
1 条回复
onsale
2018-01-16 15:27:47 +08:00
大段代码还是贴 gist/pastebin 比较好

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/423345

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX