寫了乙個稍微複雜點的sql心得

2021-05-22 09:25:42 字數 2292 閱讀 1377

select pcode from (

select h.k,h.d,h.m,h.u,l.areacode,

l.areacode||substr(h.u,4,length(h.u))||h.k pcode

from(

select j.k,j.d,j.m,j.u from(

select lpad(f,3,0) as k,d, m,u from(

select xx.areacode d,nvl(count(cy.pcode),'001')f,mx.m,mx.shopcode u

from cz_s_jtxx xx, cz_s_jtcy cy , 

( select a.m,d.shopid,d.shopcode from

(select shopid m,parentid from s_shop where shoptype=1) a,

(select shopid,parentid from s_shop where shoptype=2) b,

(select shopid,parentid from s_shop where shoptype=3)c,

(select shopid,parentid,shopcode from s_shop where shoptype=4)d

where d.parentid=c.shopid

and c.parentid=b.shopid

and b.parentid=a.m

and d.shopid=14725) mx

where xx.pcode = cy.pcode

and xx.areacode=mx.shopid

group by xx.areacode,mx.m,mx.shopcode))j)h, 

(select areacode,shopid  from cz_s_area) l 

where h.m=l.shopid)

首先 從最裡層的 sql說起:

select a.m,d.shopid,d.shopcode from

(select shopid m,parentid from s_shop where shoptype=1) a,

(select shopid,parentid from s_shop where shoptype=2) b,

(select shopid,parentid from s_shop where shoptype=3)c,

(select shopid,parentid,shopcode from s_shop where shoptype=4)d

where d.parentid=c.shopid

and c.parentid=b.shopid

and b.parentid=a.m

and d.shopid=14725

這條sql能讓我們根據機構找到最上級的shopid,和shopcode  當然這種寫法不是唯一的我們可以用oracle的

start with ...connect by prior  函式來處理這個

不過我這裡沒採用,當有了這個以後我麼能查出一條唯一的條目,根據這個條目我們可以把他看作乙個表作為子表來處理

select lpad(f,3,0) as k,d, m,u from(

select xx.areacode d,nvl(count(cy.pcode),'001')f,mx.m,mx.shopcode u

from cz_s_jtxx xx, cz_s_jtcy cy , 

( select a.m,d.shopid,d.shopcode from

(select shopid m,parentid from s_shop where shoptype=1) a,

(select shopid,parentid from s_shop where shoptype=2) b,

(select shopid,parentid from s_shop where shoptype=3)c,

(select shopid,parentid,shopcode from s_shop where shoptype=4)d

where d.parentid=c.shopid

and c.parentid=b.shopid

and b.parentid=a.m

and d.shopid=14725) mx

where xx.pcode = cy.pcode

and xx.areacode=mx.shopid

group by xx.areacode,mx.m,mx.shopcode)

乙個稍微複雜的awk sed應用

最近做了乙個文字 cdr轉換器,從 a樣式轉換為 b樣式,如下所示。a樣式 b樣式 a樣式到b樣式的轉換要點如下 1.header 和trailer 都可直接轉換,但是 b樣式需要加上 cdr的計數 2.b樣式的header 還含有record type 需要從 a樣式的某個注釋行中獲取 3.字段域...

乙個複雜的sql

select f.course node info id as nodeid,c.course node name as nodename,c.course node type as nodelevel,c.course code,case when select course node info ...

拆分乙個稍微有點複雜的字串,用c 實現

原文 字串為 3,0 5,0 6,0 7,0 8,0 9,0 需要將其拆分,首先以 拆分開,然後 3,0表示鍵值,他們是一組的,可以分別提取到。如何快速實現,泛型,陣列,請給乙個示例,謝謝。string s 3,0 5,0 6,0 7,0 8,0 9,0 regex reg new regex d,...