Search Postgresql Archives

how to write an optimized sql with two same subsql?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have a table A:
CREATE TABLE A(
ÂÂ uid integer,
ÂÂ groupid integer
)
Now we use this subsql to get each group's count:
SELECT count(*) as count
FROM A
GROUP BY groupid
ORDER BY groupid

Then we try to find the group pair with following conditions:
SELECT c.groupid as groupid1,d.groupid as groupid2
FROM subsql as c, subsql as d
WHERE d.groupid > c.groupid
ÂÂÂÂÂÂÂÂÂÂÂÂÂ and d.count > c.count;

Does that mean subsql will be executed twice? or how to write the optimized sql?



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux