zoukankan      html  css  js  c++  java
  • mysql常用sql语句

    查询字段之间的

    SELECT * FORM tables WHERE `price ` between 1000 and 2000
    between and 是包含1000和2000
    或者
    SELECT * FORM tables WHERE `price `>1000 and `price `<2000

    通过以上格式达到删除一些特殊区间的数据

    delete from tab_userinfo  where     c_numbercode>50002170 and c_numbercode<80000000
    delete from tab_userfund  where     c_numbercode>50002170 and c_numbercode<80000000;
    

      

    oracle中,创建视图的基本方式是:

    create or replace view 视图名称 as + 查询语句

    举例如下:

    --1.新建dept表的视图
    create or replace force view test_view as
    select * from dept;

    --2.查看视图
    select * from test_view;

    Mysql中查询一个表,把结果中的NULL替换成0,请写出sql语句

    mysql> select ifnull(c_createtime
    ,0) from tab_role;
    +------------------------+
    | ifnull(c_createtime,0) |
    +------------------------+
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    | 0 |
    +------------------------+
    11 rows in set
    mysql>
    

      

    SQL 用update语句一次更新多个字段应该怎么写?

    例如:
    a,b,c 是表t的3个字段,通过 条件1 和 条件2 可以分别定位到一条记录
    
    select a,b,c from t where 条件1
    select a,b,c from t where 条件2
    
    现在想把条件2 对应的记录分别修改位条件1对应的记录
    update t set a =(select a from t where 条件1),b=(select b from t where 条件1),c=(select c from t where 条件1)  where 条件2 
    
    有木有简单点的写法..  譬如
    update t set (a,b,c)=(select a,b,c from t where 条件1) where 条件2 
    求SQL大婶
    
    回答
    update a set
       a = b.a
       ,b=b.b
       ,c=b.c
    from t a,t b
    where (a.条件1) and (b.条件2)
    

      

    MySQL实现差集

    SELECT t1.c_numbercode, t1.c_username,t1.i_id
     
    FROM t1 LEFT JOIN t2 ON t1.i_id = t2.i_id
    
    WHERE t1.c_numbercode != t2.c_numbercode;
    

      

    集合操作--in的用法

    sql 查询语句 where 后面如果加多个条件 
    select * from 表 where 编号=1 2 3 4
    请问可以在=号后面加多个条件吗?可以的话语法是怎样的,还有如果不行要用什么别的办法实现呢?
    
    
    答:
    select * from 表 where 编号 in (1,2,3,4)
    或者
    select * from 表 where 编号=1 or 编号=2 or 编号=3 or 编号=4搜索
    这两个是同样的道理
    
    select c_numbercode from tab_user where c_numbercode in (select c_numbercode from t1);
    

      

    Oracle中replace函数用处

    使用的函数为replace()
    含义为:替换字符串
    replace(原字段名字,“原字段旧内容“,“原字段新内容“,)
    语句:
    update sys_frmattachmentdb  set filefullname = replace(filefullname,'历城区,'北京区)
    
    实际工作中如下使用的,在项目迁移中替换IP地址和端口等
    update edu_app t set t.jarurl = replace(t.jarurl,'124.18.198.212:8317','118.180.22.2:19080')
    update edu_app t set t.jadurl = replace(t.jarurl,'124.18.198.212:8317','118.180.22.2:19080')
    update edu_app t set t.imgurl = replace(t.jarurl,'124.18.198.212:8317','118.180.22.2:19080')
    

      

    下面是我在 实际在项目迁移中,可以用户把IP地址和端口更改的

    下面把此列的IP和端口都改成了10.0.3.25:8080

  • 相关阅读:
    Linux命令:cp (copy)复制文件或目录
    使用 robots.txt 文件阻止或删除网页说明
    ecshop优化修改sitemap.xml到根目录
    我虚拟机上装的CentOS系统显示的ip配置是127.0.0.1,请问如何解决?
    Servlet/JSP vs. ASP.NET MVC
    Ubuntu Linux 上安装Apache的过程
    Ubuntu Linux 上安装Eclipse的过程
    sudo的意义
    Dependency Injection
    Ubuntu Linux 上安装TomCat的过程
  • 原文地址:https://www.cnblogs.com/nmap/p/6724457.html
Copyright © 2011-2022 走看看