1. 程式人生 > 實用技巧 >面試之sql語句

面試之sql語句

1、從 "Websites" 表的 "country" 列中選取唯一不同的值,也就是去掉 "country" 列重複值:

select DISTINCT country from Websites

2、從 "Websites" 表中選取國家為 "CN" 的所有網站:

select * fromWebsites where country = 'CN'

3、從 "Websites" 表中選取國家為 "CN" 且alexa排名大於 "50" 的所有網站:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/    | 1     | USA     |
| 2  | 淘寶          | https://www.taobao.com/   | 13    | CN      |
| 3  | 菜鳥教程      | http://www.runoob.com/    | 4689  | CN      |
| 4  | 微博          | http://weibo.com/         | 20    | CN      |
| 5  | Facebook     | https://www.facebook.com/ | 3     | USA     |
+----+--------------+---------------------------+-------+---------+

select * from Websites where country='CN' AND alexa>50