Wednesday, December 5, 2007

How to select count distinct number of two columns in SQL?

Note count (distinct column1, column2) is invalid.

You could use self join like this:

SELECT count(*) FROM table a FULL JOIN table b ON (a.column1 = b.column1 AND a.column2 = b.column2);

You could use sub query like this:

SELECT count(*) FROM ( SELECT 1 FROM table GROUP BY column1, column 2 ) zz ;
zz is the alias for sub-SELECT

You could use || like this:

SELECT count(distinct column1||'%'||column2 ) FROM table;

Maybe should use " instead of ' in some machine. And you also could use other words other than % to avoid mistakes.

Tuesday, December 4, 2007

Be indexed by Google

Home page crawl:

Googlebot last successfully accessed your home page on Dec 2, 2007.

Also registered Google Analytics for this blog, Currently:
0 Visits
0 Pageviews

:-(

Sunday, December 2, 2007

SQL JOIN

JOIN == INNER JOIN
LEFT JOIN == LEFT OUTER JOIN
RIGHT JOIN == RIGHT OUTER JOIN
FULL JOIN == FULL OUTER JOIN


Why we use "OUTER" ???

Saturday, December 1, 2007

How to get program's directory in python?

import os

path = os.path.dirname(__file__) to get the path of .py file.

os.path.dirname returns the directory component of a pathname, __file__ is the full path of .py file.

os.path is a useful module, see the doc:
http://docs.python.org/lib/module-os.path.html