PL/SQL Case when應用
Case when應用
// 如果column_4 = 'IT_PROG' 那麼 輸出 1.10 * column_3
// 如果column_4 = 'ST_CLERK' 那麼 輸出 1.15 * column_4
// 否則 輸出 column_3 使用別名 "REVISED_SALARY"
SELECT column_1,column_2,column_3 CASE column_4 WHEN 'IT_PROG' THEN 1.10*column_3
WHEN 'ST_CLERK' THEN 1.15*column_3
WHEN 'SA_REP' THEN 1.20*column_3
ELSE column_3 END "REVISED_SALARY"
FROM table_name;
WHEN 'ST_CLERK' THEN 1.15*column_3
WHEN 'SA_REP' THEN 1.20*column_3
ELSE column_3 END "REVISED_SALARY"
FROM table_name;
//
SELECT column_1,column_2, SUM(CASE WHEN column_3 = '100' THEN column_4 ELSE 0 END) AS cost_100
FROM table_name
GROUP BY column_1,column_2;
FROM table_name
GROUP BY column_1,column_2;
// 如果 f_this_price = 0 或 f_last_price = 0 則結果為 0 ,如果都不為 0 時, 取兩列差的合計
SELECT f_wzbm,
CASE WHEN SUM(f_this_price) = 0 OR SUM(f_last_price) = 0
THEN 0
ELSE SUM(f_this_price - f_last_price)
END f_markup_price
FROM table_nameGROUP BY f_wzbm;
CASE WHEN SUM(f_this_price) = 0 OR SUM(f_last_price) = 0
THEN 0
ELSE SUM(f_this_price - f_last_price)
END f_markup_price
FROM table_nameGROUP BY f_wzbm;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1724534/viewspace-1057558/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL Case WhenSQL
- Oracle case when改寫SQLOracleSQL
- SQL中的CASE WHEN使用SQL
- sql case when, Exist ,group by ,聚合SQL
- SQL Server CASE WHEN ... THEN ... ELSE ... ENDSQLServer
- SQL Case when 的使用方法SQL
- sql中case when的小學SQL
- PLSQL條件(CASE WHEN)語句小應用SQL
- SQL中的case when then else end用法SQL
- sql server select case when的用法SQLServer
- ORACLE CASE WHEN 及 SELECT CASE WHEN的用法Oracle
- Oracle Case WhenOracle
- ORACLE SQL開發where子句之case-whenOracleSQL
- mysql case when then 使用MySql
- Oracle的order by case whenOracle
- Case when 支援變數變數
- case when遇上null值Null
- oracle plsql case when_end case小記OracleSQL
- SQL語句case when外用sum與count的區別SQL
- SQL中的case when then else end用法 【詳細】轉載SQL
- mysql中case when的使用MySql
- mysql中的case when 與if()MySql
- ORACLE多欄位CASE WHENOracle
- tcbs_批量儲存過程_sql_case when_示例儲存過程SQL
- plsql_case when_end case學習小例SQL
- 避免PL/SQL Case Not Found錯誤三方法SQL
- SQLServer使用case when中的order bySQLServer
- plsql_case when_if else endifSQL
- 案例:oracle中case when的用法Oracle
- GOTO語句在PL/SQL中的應用GoSQL
- 關於sql server case when ..else ..end結果型別的小議SQLServer型別
- 用pl/sql替代JavaSQLJava
- 用PL/SQL建立包SQL
- Oracle vs PostgreSQL Develop(30) - Index&Case whenOracleSQLdevIndex
- MySQL 的CASE WHEN 語句使用說明MySql
- oracle面試題[關於case when的用法]Oracle面試題
- PLSQL Language Referenc-PL/SQL控制語句-迴圈語句-EXIT WHENSQL
- oracle學習筆記(十七) PL/SQL高階應用Oracle筆記SQL