开发时会出现,必须写一些较复杂sql的场景
或是临时需要统计数据信息但是 开发一个统计功能有来不及的情况
也可能是报表系统组件 只支持 sql统计的情况
特地记录下这些sql 作为积累
substring 截取查询出的字符串,用于截取文件名这种把 没必要的.后缀取掉等
sql">select epa.*,epaf.*,substring(epa.voucher_file,11,INSTR(epa.voucher_file,',')-12) as files,
case when epa.payment_status =1 then '未支付'when epa.payment_status =2 then '已支付'
end as pm,
case when epa.is_backlog =0 then '已同意'when epa.is_backlog =1 then ''
end as blog,
case when epa.insurance_type ='1' then '甲类'when epa.insurance_type ='2' then '乙类'when epa.insurance_type ='3' then '丙类'when epa.insurance_type ='4' then '基药'when epa.insurance_type ='5' then '非基药'
end as intype,
case when epa.payment_method ='1' then '电汇'when epa.payment_method ='2' then '支票'when epa.payment_method ='3' then '承兑'
end as pyType from erp_purchase_advance epa left join erp_purchase_advance_form epaf on epa.id =epaf.advance_id where epa.del_flag ='0' and epa.id =:id and epa.org ='753188220495929344'
通过()让查询结果成为一个临时结果表
sql">SELECT DISTINCTnode_name,createbyName,node_id,IF (createbyName IS NULL,' ',createbyName
) AS cnm,concat(node_name,':',IF (createbyName IS NULL,' ',createbyName
)
) AS nb
FROM((SELECTa.node_name,a.id,node_idFROMaudit_node aLEFT JOIN audit_process ap ON a.audit_process_id = ap.idWHEREap.form = : typeAND a.del_flag = 0AND a.org_id = '753188220495929344'AND a.bottom_display = 1) bLEFT JOIN (SELECTaudit_node,createBy. NAME AS createbyNameFROMaudit_record arLEFT JOIN sys_user createBy ON createBy.id = ar.create_byWHEREdocument_id = : idAND STATUS = 30) r ON b.id = r.audit_node)
配合需求查看。是根据这个配置 底部显示的
去获取 已经审核完成的任务 审核人 所以要 关联 audit_record 审核记录表
sql">concat(node_name,':',IF (createbyName IS NULL,' ',createbyName
)
) AS nb
concat
用到了concat()函数,拼接生成语句
出纳付款:
后面if 如果该节点审核结束就会有审核人
如果没有就为空
那就来讲讲concat函数:
使用方法:CONCAT(str1,str2,…)
返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。