Access資料庫的多表更新方法和列變行一例

2021-06-05 11:56:35 字數 2761 閱讀 4625

(1)access資料庫的多表更新方法

x = "update " + dltb + " a inner join tbarea2 b  on a.objectid=b.fid  set a." + fd_dltb_xzdwmj + "=b.area_xzdw, a." + fd_dltb_lxdwmj + "=b.area_lxdw";

sqllist.add(x);

update dltb a inner join tbarea2 b on a.objectid=b.fid  set a.dltb_xzdwmj=b.area_xzdw,a.dltb_lxdwmj=b.area_lxdw;

(2)ytfq sql(用途分割槽) 列變行一例

select xzqdm,sum(t4) as jbntbhqmj,sum(t5) as ybndqmj,sum(t6) as czjsydqmj,sum(t7) as chzjsydqmj,sum(t8) as dlgkydqmj,

sum(t9) as fjlyydqmj,sum(t10) as sthjaqkzqmj,sum(t11) as zrywhycbhqmj,sum(t12) as lyydqmj,sum(t13) as myydqmj,

sum(t14) as qtydqmj

from

(select xzqdm,sum(fqmj) as t4,0 as t5,0 as t6,0 as t7,0 as t8,0 as t9,0 as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='010' group by xzqdm

union all

select xzqdm,0 as t4,sum(fqmj) as t5,0 as t6,0 as t7,0 as t8,0 as t9,0 as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='020' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,sum(fqmj) as t6,0 as t7,0 as t8,0 as t9,0 as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='030' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,sum(fqmj) as t7,0 as t8,0 as t9,0 as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='040' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,sum(fqmj) as t8,0 as t9,0 as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='050' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,0 as t8,sum(fqmj) as t9,0 as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='060' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,0 as t8,0 as t9,sum(fqmj) as t10,0 as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='070' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,0 as t8,0 as t9,0 as t10,sum(fqmj) as t11,0 as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='080' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,0 as t8,0 as t9,0 as t10,0 as t11,sum(fqmj) as t12, 0 as t13,0 as t14 from xb_ytfq_data where ytfqdm='090' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,0 as t8,0 as t9,0 as t10,0 as t11,0 as t12, sum(fqmj) as t13,0 as t14 from xb_ytfq_data where ytfqdm='100' group by xzqdm

union all

select xzqdm,0 as t4,0 as t5,0 as t6,0 as t7,0 as t8,0 as t9,0 as t10,0 as t11,0 as t12, 0 as t13,sum(fqmj) as t14 from xb_ytfq_data where ytfqdm='990' group by xzqdm

) as t

group by xzqdm

Access資料庫多表聯合查詢

access 資料庫多表聯合查詢 1 access 資料庫多表聯合查詢,每次連線之前須將連線符前面的內容放在括號裡面,示例如下 select 表a.欄位1,表b.欄位1,表c.欄位1,表d.欄位1 from 表a inner join 表b on 表a.欄位 表b.欄位 inner join 表c ...

Access資料庫多表連線查詢

第一次在access中寫多表查詢,就按照ms資料庫中的寫法,結果報語法錯,原來access的多表連線查詢是不一樣的 表a b c,a關聯b,b關聯c,均用id鍵關聯 一般寫法 select from a inner join b on a.id b.id inner join c on b.id c...

access資料庫更新問題

今天update access資料庫時,使用了引數化的方式,結果不報錯,但是資料也沒有更新。這問題搞了我好長時間,鬱悶,經過google發現access使用引數化時,引數位置必須和賦值順序相同才行,否則更新時就會出現資料無法更新但是也不報錯的怪現象。例如 update tablename set a...