select sc.col1, sc.col2
from
**(select col1,col from t1)** sc
where sc.col1 = (select max(col)
from
**(select col1,col from t1)**);
例如上面这种情况,在sql语句中出现两个一模一样的查询语句,在实际执行的时候会执行两次。
当然可以先将要复用的先查出来弄成临时表可以解决,但是如何用一条SQL语句来达到复用的效果,让查询优化器自动复用呢?
postgresql 实现方式