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

Thursday, November 29, 2007

Setup my adsense account

Finally I have setup my Google adsense account.
Cheers!

Wednesday, November 28, 2007

What is fairfox?

[It is copied from somewhere]

The Fairfox

The god of thought, Alger, created the Fairfox in his own mental image. In the time before mechanization, Alger believed that humans needed a sparring partner to enhance their mental abilities. To confront only the brightest of human beings, Alger created a large furry creature called the Fairfox.

The Fairfox was first made to look like an overly large fox with the most cunning mind of all magical creatures. Over time, little has changed in the Fairfox appearance; they have grown a little larger and slightly fatter than their ancestors, but they have also grown more intelligent in order to keep up with leaps in human intellectual thought.

Fairfoxes are quite particular about their habitat. They will only exist in warm forested areas and they will hibernate through any cold periods. Fairfoxes also insist on a plentiful source of fresh water nearby, as the creature is known for his fastidiously clean nature. Fairfoxes feed on wild flowers, usually pink ones, and will occasionally attack and consume particularly brainless adventurers who may seek them out.

Although Fairfoxes may have occasionally lapses in good nature, they are generally benign creatures. They will most often merely ask questions of adventures that cross their paths and even when an adventurer answer the question incorrectly, it is said that if the proper respect and admiration is given to any Fairfox, he will refrain from attacking.

It is also said that the further etiquette must be practiced when dealing with a Fairfox. The Fairfox should always be addressed as “Sir;” since there are no female Fairfoxes this is a safe title. Lore also calls for the adventurer to ask few questions, if any, of the Fairfox. They do not enjoy answering inane questions and it is nearly impossible to stump one with a riddle. It is unwise to attempt to bribe a Fairfox, unless the adventurer uses a bouquet of pink flowers. If an adventurer does succeed in answering whatever riddles the Fairfox throws at him, he should not boast to others about his deed. These claims almost always get back to the Fairfox and an angry Fairfox is a dangerous Fairfox.

The dangers laid aside, Fairfoxes are amazing intellectuals and have a wealth of knowledge at their disposal due to their long life span and frequent communication with Alger. If an adventurer can convince a Fairfox to confide in him,he is blessed indeed. Fairfoxes often know the paths to treasure and relics and since they have no interest in material goods themselves, they do not dread parting with such information as long as the adventurer has earned it.