日期:2014-05-17 浏览次数:22034 次
WITH TEMP_TAB1 AS ( SELECT 1 ID , 'MINGMING' NAME ,0 SCORE FROM DUAL UNION ALL SELECT 9 ID , 'MINGMING' NAME ,20 SCORE FROM DUAL UNION ALL SELECT 2 ID , 'HUAHUA' NAME , 80 SCORE FROM DUAL UNION ALL SELECT 3 ID , 'NIUNIU' NAME, 90 SCORE FROM DUAL UNION ALL SELECT 4 ID , 'MEI' NAME ,70 SCORE FROM DUAL UNION ALL SELECT 5 ID , 'YOU' NAME, 40 SCORE FROM DUAL ) ,TEMP_TAB2 AS ( SELECT 1 ID , 'REN' NAME , 20 SCORE FROM DUAL UNION ALL SELECT 3 ID , 'NIUNIU' NAME ,30 SCORE FROM DUAL UNION ALL SELECT 4 ID , 'RURU' NAME ,60 SCORE FROM DUAL UNION ALL SELECT 5 ID , 'HONGHONG' NAME ,0 SCORE FROM DUAL ) SELECT * FROM TEMP_TAB1 A inner JOIN TEMP_TAB2 B ON A.ID = B.ID and b.score <> 0 --and 10/a.score = 0.25 where 10/b.score = 0.5
SQL Select语句完整的执行顺序: 1、from子句组装来自不同数据源的数据; 2、where子句基于指定的条件对记录行进行筛选; 3、group by子句将数据划分为多个分组; 4、使用聚集函数进行计算; 5、使用having子句筛选分组; 6、计算所有的表达式; 7、select 的字段; 8、使用order by对结果集进行排序。
------解决方案--------------------