sql select 语句

来源:互联网 发布:数据库安全审计系统 编辑:程序博客网 时间:2024/06/14 08:42

下面就是简单的select语句,因为自己是亲自执行了,就是记录下来以后看的(但是执行之后印象更深刻不是么,估计就记在脑海中了)

A=> select * from Websites;
 id |         name         |                        url                         | alexa |  country   
----+----------------------+----------------------------------------------------+-------+------------
  2 | TaoBao               | https://www.taobao.com/                            |    13 | CN        
  1 | Google               | https://www.google.com/                            |     1 | USA       
  3 | CaiNiao              | http://www.runoob.com/                             |  4689 | CN        
  4 | WeiBo                | http://www.weibo.com/                              |    20 | CN        
  5 | FaceBook             | http://www.facebook.com/                           |     3 | USA       
(5 rows)


A=> select name from Websites;
         name         
----------------------
 TaoBao              
 Google              
 CaiNiao             
 WeiBo               
 FaceBook            
(5 rows)

A=> select id from Websites;
 id 
----
  2
  1
  3
  4
  5
(5 rows)


A=> select url from Websites;
                        url                         
----------------------------------------------------
 https://www.taobao.com/                           
 https://www.google.com/                           
 http://www.runoob.com/                            
 http://www.weibo.com/                             
 http://www.facebook.com/                          
(5 rows)


A=> select alexa from Websites;
 alexa 
-------
    13
     1
  4689
    20
     3
(5 rows)
A=> select country from Websites;
  country   
------------
 CN        
 USA       
 CN        
 CN        
 USA       
(5 rows)


下面是执行选择两个记录的语句,第一个执行结果明显报错了,第二个是对的。在选择两个记录的时候,两个column之间要用逗号隔开来。
A=> select id name from Websites;
ERROR:  syntax error at or near "name"
LINE 1: select id name from Websites;
                  ^
A=> select id,name from Websites;
 id |         name         
----+----------------------
  2 | TaoBao              
  1 | Google              
  3 | CaiNiao             
  4 | WeiBo               
  5 | FaceBook            
(5 rows)

A=> select id,name,country from Websites;
 id |         name         |  country   
----+----------------------+------------
  2 | TaoBao               | CN        
  1 | Google               | USA       
  3 | CaiNiao              | CN        
  4 | WeiBo                | CN        
  5 | FaceBook             | USA       
(5 rows)

A=> select id,alexa,country from Websites;
 id | alexa |  country   
----+-------+------------
  2 |    13 | CN        
  1 |     1 | USA       
  3 |  4689 | CN        
  4 |    20 | CN        
  5 |     3 | USA       
(5 rows)


原创粉丝点击