case when 寫在where條件中
<pre name="code" class="sql">select datas.id, datas.name, datas.memo, to_char(datas.create_date, 'yyyy-mm-dd hh24:mi:ss'), to_char(datas.create_date, 'yyyy-mm-dd hh24:mi:ss') from t_stl_s_backlog datas, (select t.id as id, t.stage as stage, (case when t.type in ('37', '38') then -- 客戶資訊 'CUSTOMER' when t.type in ('39', '40') then -- 專案資訊 'PROJECT' when t.type in ('41', '42') then -- 租賃物信 'LEASEHOLD' when t.type in ('43', '44') then -- 商業機會資訊 'OPPORTUNITY' when t.type in ('45', '46') then -- 交易資訊 'TRADEINFO' when t.type in ('47', '48') then -- 交易機會(債券) 'TRADINGOPPORTUNITY' when t.type in ('53', '54') then -- 交易機會(貸款) 'TRADINGOPPORTUNITYLOAN' when t.type in ('49', '50') then -- 租期檢查資訊 'LEASECHECK' when t.type in ('51', '52') then -- 質量分類資訊 'QUALITYCLASSIFY' else 'other' end) as typeMark from t_stl_s_backlog t inner join t_stl_s_organization organizati1_ on t.fk_organization_id = organizati1_.id where t.type in ('37', '38', '39', '40', '41', '42', '47', '48', '43', '44', '45', '46', '49', '50', '51', '52', '53', '54') and organizati1_.id in ('40280c1250ac38680150ac5845f20004', '40280c1250ac38680150ac5a74ff0007', '40280c1250ac38680150ac5afed20008', '40280c66508e2f7e01508e4133ce0000', '40280c1250ac38680150ac58235c0003', '1', '40280c96533a921c01533a9b2be30000', '40280c96533a921c01533a9c40fb0001', '4028d08154c86e630154c8c5804e0001') and to_char(t.end_date, 'yyyy-mm-dd hh24:mi:ss') >= '2016-08-24 00:00:00') data1, (select nvl(max(a.analyze_customer), 0) as analyze_customer, --客戶分析階段 nvl(max(a.censor_customer), 0) as censor_customer, --客戶審查階段 nvl(max(a.compliance_review_project), 0) as compliance_review_project, -- 專案合規審查階段 nvl(max(a.dispose_leasehold), 0) as dispose_leasehold, -- 租賃物處置階段 nvl(max(a.due_diligence_project), 0) as due_diligence_project, --專案盡職調查階段 nvl(max(a.examine_project), 0) as examine_project, -- 專案專案審批階段 nvl(max(a.factor_contract), 0), nvl(max(a.finish_contract), 0), nvl(max(a.initiation_opportunity), 0) as initiation_opportunity, -- 商業機會專案立項階段 nvl(max(a.insure_leasehold), 0) as insure_leasehold, -- 租賃物保險階段 nvl(max(a.intervene_opportunity), 0) as intervene_opportunity, -- 商業機會前期介入階段 nvl(max(a.investigate_customer), 0) as investigate_customer, -- 客戶調查階段 nvl(max(a.manage_leasehold), 0) as manage_leasehold, -- 租賃物租期管理階段 nvl(max(a.prepare_contract), 0), nvl(max(a.pricing_leasehold), 0) as pricing_leasehold, -- 租賃物認定及定價階段 nvl(max(a.register_leasehold), 0) as register_leasehold, -- 租賃物交接及登記階段 nvl(max(a.sign_contract), 0), nvl(max(a.sign_project), 0) as sign_project, -- 專案 簽約付款階段 nvl(max(a.start_contract), 0), nvl(max(a.contact_customer), 0) as contact_customer, -- 客戶聯絡階段 nvl(max(a.project_start), 0), nvl(max(a.review_project), 0) as review_project, -- 專案評審審查階段 nvl(max(a.cancel_guarantee_contract), 0), nvl(max(a.prepare_guarantee_contract), 0), nvl(max(a.sign_guarantee_contract), 0), nvl(max(a.commu_trading_opportunity), 0) as commu_trading_opportunity, -- 交易機會溝通階段 nvl(max(a.init_trading_opportunity), 0) as init_trading_opportunity, -- 交易機會立項階段 nvl(max(a.finish_financing_contract), 0), nvl(max(a.prepare_financing_contract), 0), nvl(max(a.sign_financing_contract), 0), nvl(max(a.credit_apply), 0) as credit_apply, -- 交易授信申請階段 nvl(max(a.credit_approve), 0) as credit_approve, -- 交易授信獲批階段 nvl(max(a.credit_end), 0) as credit_end, -- 交易授信到期階段 nvl(max(a.credit_start), 0) as credit_start, -- 交易授信使用階段 nvl(max(a.analysis_lease_check), 0) as analysis_lease_check, -- 租期檢測的分析階段 nvl(max(a.analysis_quality_classify), 0) as analysis_quality_classify, -- 質量分類初分階段 nvl(max(a.approve_quality_classify), 0) as approve_quality_classify, -- 質量分類中分階段 nvl(max(a.execute_lease_check), 0) as execute_lease_check, -- 租期檢查執行階段 nvl(max(a.plan_lease_check), 0) as plan_lease_check, -- 租期檢測的計劃階段 nvl(max(a.plan_quality_classify), 0) as plan_quality_classify -- 質量分類計劃階段 from (select qx.*, zjb.user_id as fk_user_id from T_STL_S_POSITION_PRIVILEGE qx, T_STL_S_POSITION gw, T_STL_S_USER_POSITION zjb where zjb.user_id = '4028ef8156a07f530156a08b3cb3010b' and zjb.position_id = gw.id and gw.fk_privilege_id = qx.id) a group by a.fk_user_id) data2 where datas.id = data1.id -- 建立階段與崗位許可權的對映關係 and (case -- 客戶階段許可權 when data1.typeMark = 'CUSTOMER' and data1.stage = '1' then -- 開始階段對應的是客戶聯絡階段 data2.contact_customer when data1.typeMark = 'CUSTOMER' and data1.stage = '2' then -- 聯絡階段對應的是客戶聯絡階段 data2.contact_customer when data1.typeMark = 'CUSTOMER' and data1.stage = '3' then -- 調查階段對應的是客戶調查階段 data2.investigate_customer when data1.typeMark = 'CUSTOMER' and data1.stage = '4' then -- 審查階段對應的是客戶審查階段 data2.censor_customer when data1.typeMark = 'CUSTOMER' and data1.stage = '5' then -- 分析階段對應的是客戶分析階段 data2.analyze_customer when data1.typeMark = 'CUSTOMER' and data1.stage = '6' then -- 結束階段對應的是客戶分析階段 data2.analyze_customer -- 專案 when data1.typeMark = 'PROJECT' and data1.stage = '1' then -- 開始階段對應的是專案開始階段 data2.due_diligence_project when data1.typeMark = 'PROJECT' and data1.stage = '2' then -- 盡職調查階段對應的是專案盡職調查階段 data2.due_diligence_project when data1.typeMark = 'PROJECT' and data1.stage = '3' then -- 合規審查階段對應的是專案合規審查階段 data2.compliance_review_project when data1.typeMark = 'PROJECT' and data1.stage = '4' then -- 評審審查階段對應的是專案評審審查階段 data2.review_project when data1.typeMark = 'PROJECT' and data1.stage = '5' then -- 專案審批階段對應的是專案專案審批階段 data2.examine_project when data1.typeMark = 'PROJECT' and data1.stage = '6' then -- 簽約付款階段對應的是專案簽約付款階段 data2.sign_project when data1.typeMark = 'PROJECT' and data1.stage = '7' then -- 結束階段對應的是專案簽約付款階段 data2.sign_project -- 租賃物 when data1.typeMark = 'LEASEHOLD' and data1.stage = '1' then -- 開始階段對應的是租賃物認定及定價階段 data2.pricing_leasehold when data1.typeMark = 'LEASEHOLD' and data1.stage = '2' then -- 認定及定價階段對應的是租賃物認定及定價階段 data2.pricing_leasehold when data1.typeMark = 'LEASEHOLD' and data1.stage = '3' then -- 交接及登記價階段對應的是租賃物交接及登記階段 data2.register_leasehold when data1.typeMark = 'LEASEHOLD' and data1.stage = '4' then -- 保險價階段對應的是租賃物保險價階段 data2.insure_leasehold when data1.typeMark = 'LEASEHOLD' and data1.stage = '5' then -- 租期管理階段對應的是租賃物租期管理階段 data2.manage_leasehold when data1.typeMark = 'LEASEHOLD' and data1.stage = '6' then -- 處置階段對應的是租賃物處置階段 data2.dispose_leasehold when data1.typeMark = 'LEASEHOLD' and data1.stage = '7' then -- 結束階段對應的是租賃物處置階段 data2.dispose_leasehold -- 商業機會 when data1.typeMark = 'OPPORTUNITY' and data1.stage = '1' then -- 開始階段對應的是商業機會前期介入階段 data2.intervene_opportunity when data1.typeMark = 'OPPORTUNITY' and data1.stage = '2' then -- 前期介入階段對應的是商業機會前期介入階段 data2.intervene_opportunity when data1.typeMark = 'OPPORTUNITY' and data1.stage = '3' then -- 專案立項階段對應的是商業機會專案立項階段 data2.initiation_opportunity when data1.typeMark = 'OPPORTUNITY' and data1.stage = '4' then -- 結束階段對應的是商業機會專案立項階段 data2.initiation_opportunity -- 交易資訊 when data1.typeMark = 'TRADEINFO' and data1.stage = '1' then -- 開始階段對應的是交易授信申請階段 data2.credit_apply when data1.typeMark = 'TRADEINFO' and data1.stage = '2' then -- 授信申請階段對應的是交易授信申請階段 data2.credit_apply when data1.typeMark = 'TRADEINFO' and data1.stage = '3' then -- 授信獲批階段對應的是交易授信獲批階段 data2.credit_approve when data1.typeMark = 'TRADEINFO' and data1.stage = '4' then -- 授信使用階段對應的是交易授信使用階段 data2.credit_start when data1.typeMark = 'TRADEINFO' and data1.stage = '5' then -- 授信到期階段對應的是交易授信到期階段 data2.credit_end when data1.typeMark = 'TRADEINFO' and data1.stage = '6' then -- 結束階段對應的是交易授信到期階段 data2.credit_end -- 交易機會 (債券) when data1.typeMark = 'TRADINGOPPORTUNITY' and data1.stage = '1' then -- 開始階段對應的是交易機會溝通階段 data2.commu_trading_opportunity when data1.typeMark = 'TRADINGOPPORTUNITY' and data1.stage = '2' then -- 溝通階段對應的是交易機會溝通階段 data2.commu_trading_opportunity when data1.typeMark = 'TRADINGOPPORTUNITY' and data1.stage = '3' then -- 立項階段對應的是交易機會立項階段 data2.init_trading_opportunity when data1.typeMark = 'TRADINGOPPORTUNITY' and data1.stage = '4' then -- 結束階段對應的是交易機會立項階段 data2.init_trading_opportunity -- 交易機會 (貸款) when data1.typeMark = 'TRADINGOPPORTUNITYLOAN' and data1.stage in ('1', '2', '3') then -- 開始、溝通、結束 階段對應的是交易機會溝通階段 data2.commu_trading_opportunity -- 租期檢查 when data1.typeMark = 'LEASECHECK' and datas.entity_id = (select tsl.id from T_STL_S_LEASE_CHECK tsl, T_STL_S_LEASE_CHECK_USER tslu where tsl.id = datas.entity_id and tslu.lease_check_id = tsl.id and tslu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '1' then -- 開始階段對應的是租期檢測的計劃階段 data2.plan_lease_check when data1.typeMark = 'LEASECHECK' and datas.entity_id = (select tsl.id from T_STL_S_LEASE_CHECK tsl, T_STL_S_LEASE_CHECK_USER tslu where tsl.id = datas.entity_id and tslu.lease_check_id = tsl.id and tslu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '2' then -- 計劃階段對應的是租期檢測的計劃階段 data2.plan_lease_check when data1.typeMark = 'LEASECHECK' and datas.entity_id = (select tsl.id from T_STL_S_LEASE_CHECK tsl, T_STL_S_LEASE_CHECK_USER tslu where tsl.id = datas.entity_id and tslu.lease_check_id = tsl.id and tslu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '3' then -- 執行階段對應的是租期檢測的執行階段 data2.execute_lease_check when data1.typeMark = 'LEASECHECK' and datas.entity_id = (select tsl.id from T_STL_S_LEASE_CHECK tsl, T_STL_S_LEASE_CHECK_USER tslu where tsl.id = datas.entity_id and tslu.lease_check_id = tsl.id and tslu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '4' then -- 分析階段對應的是租期檢測的分析階段 data2.analysis_lease_check when data1.typeMark = 'LEASECHECK' and datas.entity_id = (select tsl.id from T_STL_S_LEASE_CHECK tsl, T_STL_S_LEASE_CHECK_USER tslu where tsl.id = datas.entity_id and tslu.lease_check_id = tsl.id and tslu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '5' then -- 分析階段對應的是租期檢測的分析階段 data2.analysis_lease_check --質量分類 when data1.typeMark = 'QUALITYCLASSIFY' and datas.entity_id = (select tsq.id from T_STL_S_QUALITY_CLASSIFY tsq, T_STL_S_QUALITY_CLASSIFY_USER tsqu where tsq.id = datas.entity_id and tsqu.quality_classify_id = tsq.id and tsqu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '1' then -- 開始階段對應的是質量分類的計劃階段 data2.plan_quality_classify when data1.typeMark = 'QUALITYCLASSIFY' and datas.entity_id = (select tsq.id from T_STL_S_QUALITY_CLASSIFY tsq, T_STL_S_QUALITY_CLASSIFY_USER tsqu where tsq.id = datas.entity_id and tsqu.quality_classify_id = tsq.id and tsqu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '2' then -- 計劃階段對應的是質量分類的計劃階段 data2.plan_quality_classify when data1.typeMark = 'QUALITYCLASSIFY' and datas.entity_id = (select tsq.id from T_STL_S_QUALITY_CLASSIFY tsq, T_STL_S_QUALITY_CLASSIFY_USER tsqu where tsq.id = datas.entity_id and tsqu.quality_classify_id = tsq.id and tsqu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '3' then -- 初分階段對應的是質量分類的初分階段 data2.analysis_quality_classify when data1.typeMark = 'QUALITYCLASSIFY' and datas.entity_id = (select tsq.id from T_STL_S_QUALITY_CLASSIFY tsq, T_STL_S_QUALITY_CLASSIFY_USER tsqu where tsq.id = datas.entity_id and tsqu.quality_classify_id = tsq.id and tsqu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '4' then -- 終分階段對應的是質量分類的終分階段 data2.approve_quality_classify when data1.typeMark = 'QUALITYCLASSIFY' and datas.entity_id = (select tsq.id from T_STL_S_QUALITY_CLASSIFY tsq, T_STL_S_QUALITY_CLASSIFY_USER tsqu where tsq.id = datas.entity_id and tsqu.quality_classify_id = tsq.id and tsqu.user_id = '4028ef8156a07f530156a08b3cb3010b') and data1.stage = '5' then -- 結束階段對應的是質量分類的終分階段 data2.approve_quality_classify -- 如果上面的條件不滿足 則不應該展示資料 else 2 end) = 1 order by datas.create_date desc;
相關推薦
mysql中使用case when 做where條件篩選表記錄
平時我們專案中經常用到 where 欄位名=值 來篩選查詢結果,但實際也會遇到這樣的情況,如果表中某個欄位code的值是“_1”結尾的,那麼就查全部,否則,根據輸入的引數查詢。 這時 case when 就派上用途了: select * from ta
oracle 在where條件中寫case when
業務:當狀態等於2時判斷表中的userid 是否和當前登入人id相等 SELECT * FROM tbname t WHERE 1=1AND (CASE WHEN t.vc_state = '2' THEN t.vc_userId ELSE 當前登入人id
case when 寫在where條件中
<pre name="code" class="sql">select datas.id, datas.name, datas.memo, to_char(datas.create_date, 'yyyy-mm-dd h
SQLServer2008 在where條件中使用CASE WHEN
where (case when LEN(A.startMonth)=1 and A.startMonth!=0 then cast((CAST(startYear as varchar(4))+'0'+cast(A.startMonth as varchar(1))) as date) wh
oracle如何在where條件中寫日期?
sql如下: SELECT * FROM T_QUERY_LOG t WHERE t.CREATEDATE >= to_date('2016-7-1','yyyy-mm-dd') AND t.
【sql技巧】mysql修改時,動態指定要修改的字段 update `table` set (case when ....) = 1 where id = xx
幫助 ase stack pan 希望 需求 記錄 開始 lec 如果你點進了這篇帖子,那麽你一定遇到了跟我一樣的問題。別看題目的set case when...,我一開始也是第一反應是用case when但是發現並不好使。 問題呢,說得高大上一點:動態指定要修改的字段。
SQL利用Case When Then多條件
sum mage 需要 而且 例如 user 英國 根據 來看 CASE WHEN 條件1 THEN 結果1 WHEN 條件2 THEN 結果2 WHEN 條件3 THEN 結果3 WHEN 條件4 THEN 結果4......... WHEN
026.Sql排序和寫Where條件
mysql 開啟 slow_query_log_file,看到以下查詢超過1s。 對於的mybatis檔案如下。 sql慢,幾乎都和索引有關。 索引情況 值的分佈區間較少,索引意義不大。如is_deleted,一看就是bool值。 null 特殊,不參與計算,統計,索引不好。 比
SQL case when then end根據某列資料內容在新列顯示自定義內容 SQL利用Case When Then多條件判斷SQL 語句
select ID,Username,namer=(case when(score<='50') then '實習' when(score>'50' and score<='500' ) then
在Linq的Where條件中,如何優雅的進行型別轉換?
大家應該都知道Int32.Parse()是不安全,但有時可能會有僥倖心理,而我正是在這樣的心理驅使下,這麼幹了。相關場景簡化處理後的程式碼,如下。 List<BookInfo> bookLst = new List<BookInfo>();
T-SQL語句之case when then 多條件判斷
CASE WHEN 條件1 THEN 結果1 WHEN 條件2 THEN 結果2 WHEN 條件3 THEN 結果3 WHEN 條件4 THEN 結果4 ......... WHEN 條件N THEN 結果N ELSE 結果X END Case具有兩種格式。簡單Case函
【mysql】mysql case when實現不同條件查詢
程式碼示例 SELECT SUM(CASE WHEN e.cost_audit_type = 1 AND date_format(e.cost_audit_time, '%Y-%m') = '2
sql T_sql 利用Case When Then多條件判斷SQL 語句
SQL語句中的CASE語句與高階語言中的switch語句,是標準SQL的語法,適用與一個條件判斷有多種值的情況下分別執行不同的操作。 靈活應用CASE語句可以使SQL語句變得簡潔易讀,下面我們通過幾個例子來認識它。 select* from dbo.storeB select bname,price
oracle sql 語句中where條件中 1=1 是什麼意思
是為了後面附加and ...方便程式邏輯處理用的, 要不然你就得稍微複雜一點兒處理: 有where條件。。。 沒有where條件。。。 1=1 是永恆成立的,意思無條件的,也就是說在SQL語句裡有沒有這個1=1都可以。 這個1=1常用於應用程式根據使用者選擇項的不
where 條件中 使用 instr 替代 in
select * from expense ee where ee.pro_ype = processType and ee.cost_type in ( SELECT tt.value FROM t_enum tt where tt.enum_name =
hive case when then 多條件
select substr(key,13,2), case when birthday<'1968' then '50up' when birthday<'1978' then '40-5
SQL利用Case When Then多條件判斷
CASE WHEN 條件1 THEN 結果1 WHEN 條件2 THEN 結果2 WHEN 條件3 THEN 結果3 WHEN 條件4 THEN 結果4......... WHEN 條件N THEN 結果N ELSE 結果XEND Case
mysql max函式不能用在where條件中的案例
案例背景: 版主在"mysql表的字符集uft8轉換成gbk測試"一文中,blog位置 欄位最大長度等於22個字元的記錄,將max(char_length(CUSTOMER_NAME))=22直接放在where條件中,但執行報 錯。 (product)[email
2、SQL Server:SQL利用Case When Then多條件判斷SQL 語句
第一種:select ID,(case when 條件一 and 條件二 then 0 when 條件三 and 條件四 then 1 else 2 end) as count,name from tablename
sql-case,when的多條件組合寫法
1.decode 寫法簡介,只能寫表示式。 例:decode(表示式,條件1,值1,條件2,值2··· 預設值) 無法滿足多條件的寫法,比如,我要a-b = 0 且a !=0 用decode沒法實現 2.case when 能寫多條件 寫法一:case 表示式 wh