SELECT * FROM Websites;
SELECT name,country FROM Websites;
SELECT DISTINCT country FROM Websites;(仅从 "Websites" 表的 "country" 列中选取唯一不同的值,也就是去掉 "country" 列重复值)
SELECT * FROM Websites WHERE country='CN';
SELECT * FROM Websites WHERE country='CN' AND alexa > 50;
SELECT * FROM Websites WHERE country='USA' OR country='CN';
SELECT * FROM Websites WHERE alexa > 15 AND (country='CN' OR country='USA');
SELECT * FROM Websites ORDER BY alexa;
SELECT * FROM Websites ORDER BY alexa DESC;
SELECT * FROM Websites ORDER BY country,alexa;
ORDER BY 多列的时候,先按照第一个column name排序,在按照第二个column name排序;如上述教程最后一个例子:
- 1)、先将country值这一列排序,同为CN的排前面,同属USA的排后面;
- 2)、然后在同属CN的这些多行数据中,再根据alexa值的大小排列。
- 3)、ORDER BY 排列时,不写明ASC DESC的时候,默认是ASC。