`
david_je
  • 浏览: 373197 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

查询数据

阅读更多
SELECT语句用来从数据表中检索信息。语句的一般格式是:
SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy;

1.查询所有数据
 
select * from pet;

2.查询特殊行
 
SELECT * FROM pet WHERE name = 'Bowser';
SELECT * FROM pet WHERE birth > '1998-1-1';
SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';  
AND和OR可以混用,但AND比OR具有更高的优先级。如果你使用两个操作符,使用圆括号指明如何对条件进行分组
SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm') OR (species = 'dog' AND sex = 'f');
  

3.查询唯一记录使用关键字DISTINCT
 
SELECT DISTINCT owner FROM pet;

4.排序
 
顺序:SELECT name, birth FROM pet ORDER BY birth;
逆序:SELECT name, birth FROM pet ORDER BY birth desc;


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics