zoukankan      html  css  js  c++  java
  • 常用几个SQL语句(增删改查)

    --创建一个学生测试表
    create table teststu(
     no char(2),
     name char(4),
     age  number(2)
    );
    --insert 插入数据 insert into 表名(列名1,列名2...) values(数据1,数据2...);
     insert into teststu values('10','黎明',19);
     insert into teststu values('11','李明',18);
     insert into teststu values('12','张明',21);
     insert into teststu values('13','张三',22);
     insert into teststu values('13','周三',20);
     insert into teststu values('13','李思',17);
     insert into teststu values('15','李思',17);
     --改数据 update 表名 set 列1名字=更新值,列2名字=更新值...
      -- where 更新条件
      update teststu set no='14'
    	   where name='周三';
     -- 删除数据 delete from 表名 where 删除条件
      delete  from teststu 
    	   where no='15';
     -- distinct (在查询的结果集中去掉重复行,不改变表内容)
       select distinct no from teststu
    	   order by no asc;	 --升序排序
     -- 查询 select 列名 from 表名;*表示所有列
      select * from teststu;
    	select no,name from teststu;
     --查询排序(升序) order by 列名 asc;下面列子表示如果no相同,则比较age
         select * from teststu t
    		  -- where t.age>=18
    			  order by t.no asc,t.age asc;
     --select case when 语句
     --第一种
      select t.no,t.name,t.age,(
    	 case t.age
    		 when 17 then 23
    		 when 18 then 24
    			 else t.age
    				 end
    	)from teststu t;		 
     --update case when 语句
      update teststu t set t.age=(
    	 case t.age
    		  when 17 then 23
    	    when 18 then 24
    			 else t.age
    				 end
    	);
     
       update teststu t set t.no=
    	 case when t.age='23'then t.no='15'
    			 else t.no
    				 end;
    	
    

      

  • 相关阅读:
    LightOJ--1094-- Farthest Nodes in a Tree(树的直径裸题)
    poj--1383--Labyrinth(树的直径)
    C字符数组和C++字符串
    Miracl库学习
    GBDT学习
    Java编程规范
    关于JS中的数组[]的方法
    焦点离开事件
    Firebug 安装方法
    JAVASE 中的String的字符串
  • 原文地址:https://www.cnblogs.com/ysg520/p/9665739.html
Copyright © 2011-2022 走看看