`

几个简单的sql 不常写就容易忘记

阅读更多
一.说明 几个简单的基本的sql语句,不常写,就容易忘记。

1.查询  select * from table1 where 范围
2.插入  insert into table1 (field1,field2)values(value1,value2)
3.删除  delete from table1 where 范围
4.更新  update table1 set field1=value1 ,field2= value2 where 范围
5.like查询 select * from table1 where filed1 like '%value1%'
6.排序 select * from table1 order by filed1 desc [or asc]
7.总数 select count(*) as totalcount from table1
8.求和 select sum(field1) as sumvalue from table1
9.平均 select avg(field1) as avgvalue from table1
10.最大 select max(field1) as maxvalue from table1
11.最小 select min(field1) as minvalue from table1

   ----between and ----  
 eg:
 select * 
	from table1
		 where salary 
		 		between 2000 and 5000
		 		
 select *
     from table1 
     	where salary >=2000 and salary <=5000
		 		
    
  ----or ----
 eg:
 select tname,dname,sal
        from teacher 
             where dname='计算机' 
             	  or dname='生物'
             	     order by dname 
 

 
   ----not in ----  
 eg:
 select tname,dname,sal,age
        from teacher 
             where dname
             	 not in('计算机','生物','机械工程')
             	 		order by dname 
 
 
 
    ----not ----  
 eg:
 select tname,dname,sal,age
        from teacher 
             where 
             	 not dname = '计算机'
             	 		order by dname 
 select tname,dname,sal,age
        from teacher 
             where 
             	 not sal > 1500
             	 		order by dname 
             	 		
             	 		
  -----------<> not != --------

not 可以有其他运算符组合查询
eg:
 select tname,dname,sal,age
        from teacher 
             where 
             	 not age between 40 and 50
             	 		order by dname 
             	 		
     	
     	
             	     
             	     
    

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics