zoukankan      html  css  js  c++  java
  • 面试笔试题:多表关联的update语句、将in中的查询条件按顺序输出和SQL语句增加列、修改列、删除列

    以下都是oracle的编写方式,其余数据库在网上很容易找到,就不写了。

    1、将in中的查询条件按顺序输出,可以使用order by decode 有语句,加条件的id顺序

    举例:

      select * from serv_t where serv_id in (957194,965707,960028,6014325) order by decode (serv_id,957194,1,965707,2,960028,3,6014325,4)

    2、多表关联的update,修改一个字段,使用exists关键字

      1)直接给set字段值

        update serv_t a set a.product_id='222' where exists (select * from cust_t b where a.cust_id=b.cust_id and a.serv_id=957194)

      2)被修改的值由另一个表运算而来

        update customers a  set   city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)       

        where  exists (select 1 from   tmp_cust_city b where  b.customer_id=a.customer_id)

    3、多表关联的update,修改两个字段(以上),被修改的值由另一个表运算而来

      1)update customers a  set  (city_name,customer_type)=(select b.city_name,b.customer_type from  tmp_cust_city b 

         where  b.customer_id=a.customer_id) where  exists (select 1 from tmp_cust_city b where  b.customer_id=a.customer_id)

    4、SQL语句增加列、修改列、删除列

      1)增加列:alter table tableName add columnName varchar(30)

      2)修改列类型:alter table tableName alter column columnName varchar(4000)

      3)修改列的名称:EXEC sp_rename 'tableName.column1' , 'column2' ;#(把表名为tableName的column1列名修改为column2)

      4)删除列:alter table tableName drop column columnName

  • 相关阅读:
    Adobe Photoshop cs6 破解方法
    vs2008试用90天破解方法
    Install win8_pro using UltraISO
    面试题-100盏灯问题
    PHP 博客文集 1 Veda原型 成功,唯有积累,没有奇迹
    php 框架
    php 语法2
    干货 连接
    试题 极客学院
    地图
  • 原文地址:https://www.cnblogs.com/huangguabushihaogua/p/11427961.html
Copyright © 2011-2022 走看看