在計算收益率時候, 收益率 = 收益 / 成本
一、如果成本為0,NULL,此時無法計算收益率;
方法:
1.將成本為0的數據 運算
(case when cost =0 or cost is null then 0 else income/cost end) as yeild;
select account,sum(case when amount1 is null then 0 else amount1 END) as total,init_date
from data_stock1 GROUP BY account,init_date;
SELECT account, CASE WHEN min(amount1) <= 0 THEN '零' WHEN min(amount1) <= 100 THEN '十' WHEN min(amount1) <= 1000 THEN '百' ELSE '百以上' END AS 級別, init_date FROM data_stock1 GROUP BY account, init_date;
2.處理數據為NULL時的運算:
將數據轉化為 0; nvl(cost, 0) as cost;
3.四舍五入
round(cost,4)
4.取整
ceil(cost)
floor(cost)
二、計算數據
三、探討UNION ALL與FULL JOIN ON 運用同一場景的效率問題
[轉]http://www.zhixing123.cn/net/27495.html
一、查詢執行最慢的sql
select * from (select sa.SQL_TEXT, sa.SQL_FULLTEXT, sa.EXECUTIONS "執行次數", round(sa.ELAPSED_TIME / 1000000, 2) "總執行時間", round(sa.ELAPSED_TIME / 1000000 / sa.EXECUTIONS, 2) "平均執行時間", sa.COMMAND_TYPE, sa.PARSING_USER_ID "用戶ID", u.username "用戶名", sa.HASH_VALUE from v$sqlarea sa left join all_users u on sa.PARSING_USER_ID = u.user_id where sa.EXECUTIONS > 0 order by (sa.ELAPSED_TIME / sa.EXECUTIONS) desc)where
rownum <= 50;
二、查詢次數最多的 sql
select * from (select s.SQL_TEXT, s.EXECUTIONS "執行次數", s.PARSING_USER_ID "用戶名", rank() over(order by EXECUTIONS desc) EXEC_RANK from v$sql s left join all_users u on u.USER_ID = s.PARSING_USER_ID) t where exec_rank <= 100;
四、關於兩表出現 null值的字段加減