創建SQL視圖編碼
create OR REPLACE VIEW c4 as ---創建試圖C4 select custcode, CONCAT(substr(0000000000,-(length(custcode)-length(custcode+1))),custcode+1) custcode2, id, CAST(id as int) ID2, ---把編碼右三位的列轉換成數字 custname, areaclcode, pk_areacl from ( select custcode, replace (substr(custcode,-4),'*','0' ) id, ---把編碼右三位取出來 custname, areaclcode, pk_areacl from ( select custcode , custname , areaclcode, bd_cubasdoc.pk_areacl from bd_cubasdoc,bd_areacl where bd_cubasdoc.pk_areacl=bd_areacl.pk_areacl )aa where areaclcode like '07%' ---取地區分類07開頭的行 )a ; create OR REPLACE VIEW c5 as ---創建試圖C5 select t1.maxid,t1.areaclcode,t2.custcode,t2.custcode2,t2.id,t2.custname,pk_areacl --取C4表的值和分組統計的值 from ( select MAX(id2) maxid,areaclcode from c4 group by areaclcode ---根據地區分類分組,取ID2列(把編碼右三位的列轉換成數字)最大值 )t1 left join c4 t2 on t1.maxid=t2.id2 and t1.areaclcode=t2.areaclcode ---表和視力的ID和地區分類名稱都要相等
查詢 C5spa
select * from C5
客商申請單 地區分類 增長編輯公式code
custcode->getColValue(C5,custcode2,pk_areacl,pk_areacl)blog