sql 笔记

  1. select DATE_FORMAT(news_table.news_time, '%Y-%m-%d %H:%i:%s') news_time,   
  2. news_table.flag, news_table.id, news_table.iconCls, news_table.news_title,  
  3.  news_table.news_content, news_table.news_filepath, news_table.news_publictime,  
  4.   user_table.user_real news_author, newstype_table.newstype_type news_type,   
  5.   news_table.news_other, news_table.news_isPublic from news_table, newstype_table,  
  6.    user_table where news_table.news_type = newstype_table.id   
  7. and news_table.news_author = user_table.user_name order by news_time DESC limit 10,10  
  8.  -- 数据格式化  DATE_FORMAT  
  9. SELECT * FROM meeing_record_table WHERE m_rd_id = 1 AND !FIND_IN_SET('004',repersion)   
  10. -- 查询指定列不存在指定值的记录  
  11. UPDATE  shengyoubian SET shengyoubian.youbian = ''+RIGHT(shengyoubian.youbian,6)  
  12. UPDATE  shengyoubian SET shengyoubian.youbian = ''+LEFT(shengyoubian.youbian,6)  
  13. -- 更新指定列值 为截取的值.  
  14. SELECT SUBSTRING_INDEX(shengyoubian.youbian,'2',1);  
  15. -- 查询索引值   
  16. UPDATE user_table SET xb='1'WHERE SUBSTR(sfz,17,1)%2=1  
  17. -- 身份证更新性别   截取指定值..  
  18. UPDATE user_file_table SET rePersion=REPLACE(rePersion, ',1010''')  
  19. -- 通过更新的方法删除指定参数..  
  20.   
  21. {  
  22. UPDATE  shengyoubian  
  23. -- SET shengyoubian.youbian = ''+RIGHT(shengyoubian.youbian,6)  
  24. SET shengyoubian.dizhi=  
  25. --  ''+RIGHT(str,len)  
  26. REPLACE(shengyoubian.dizhi,shengyoubian.youbian,'')  
  27. }-- 更新A列值去除B列已有的字符  
  28.   
  29. {  
  30. Select a.dept_id, a.station_no,a.flag, a.xz_flag, b.`nameAS dept_name  
  31. FROM dept_station_table AS a ,department_table AS by  
  32. Where a.dept_id >=(Select dept_id From dept_station_table  limit 0,1)  AND  a.dept_id = b.dept_id limit 5;  
  33. }-- 较好的一种查询分页方式.先比较在截取  
  34.   
  35. IF('条件','true','false'AS checked  
  36. --条件查询                
  37.   
  38.   
  39. -- show ENGINES ;  
  40. -- SHOW VARIABLES LIKE 'have%';  
  41. -- show VARIABLES LIKE 'storage_engine'  
  42. -- DESC user_table;  
  43. -- ALTER TABLE user_table ad VARCHAR(10) NULL AFTER  FIRST  
  44. -- ALTER TABLE user_table DROP '列名'  
  45. SELECT youbian ,GROUP_CONCAT(dizhi) FROM shengyoubian GROUP BY youbian;--分组查询 重复数据显示在后方.. ','连接  
  46.   
  47. SELECT youbian ,GROUP_CONCAT(dizhi) AS dizhi ,COUNT(dizhi) AS cou FROM shengyoubian GROUP BY youbian with ROLLUP;   
  48. -- with ROLLUP 计算每组的记录数  
  49. SELECT * FROM shengyoubian  WHERE youbian REGEXP '^257'  
  50. -- 正则表达式匹配 ^开始 $结束 .任意一个字符包括 回车/换行 [字符集] [^除了字符集]  S1|S2|S3 任意一个字符串   
  51.     --   * 多个之前的字符 包括0和1  +代表多个字符之前的字符 包括1   字符串{N}字符串出现N次    
  52.         -- 字符串[M,N] 字符串至少 M次 最多 N次   
  53. Insert Into table_A (A ,B ) Select Aa AS A ,Bb as b from tabe_B    
  54. -- 查询B表中的值添加到A表  
  55. Select A+B+C as a from tabe_B   
  56. -- 算数运算符 + - * /  DIV(同/)   % MOD (取余)  
  57. -- = <> <=> IS NULL IS NOT NULL IN LIKE   
  58. -- && AND       ||  OR   !  XOR   
  59. --  按位 & | ~  与或非  >> <<   
  60. -- 函数 绝对值 ABS(X)  CEIL(X) '获取整数' CEILING(X) SIGN(-1|0|1)  SIN(X) COS(X) TAN(X)  RAND(x)'获取随机数'   
  61. -- ROUND(x) 四舍五入 ROUND(x.m) m 位小数 TRUNCATE(A.B) 截取B位小数   幂运算POW(x,y)  
  62.       
  63. -- CHAR_LENGTH(S) 字符串的字符数  
  64. -- LENGTH(S) 字符串的长度   
  65. -- LEFT(S,N)          RIGHT(S,N)     LTRIM(S) 去掉开始的空格  INSERT(s,s1)从s字符串查找 s1的位置   
  66. -- REVERSE(s) 将字符串S的顺序反过来  SUBSTRING(S,N,Len) 截取字符串 MID(s,n,len) CONCAT(s1,s2) 合并字符串  
  67.   
  68. select a, DATE_FORMAT(b,'Y-m-d'from user_table;  
  69. -- 日期时间格式化     
  70. Select IF(a>10 ,'pass','false'from user_table;  
  71. -- if函数   
  72. Select IFNULL(a,'默认值'from user_table;  
  73. -- IFNULL 函数  
  74. Select a , CASE a when 90 then "默认值" when 80 then '' ELSE '' END AS ''  FROM user_table;  
  75. -- CASE 函数  
  76. -- 系统参数 version()  connection_id() user()   
  77.   
  78. -------------------------------  
  79. Select PASSWORD(str);  
  80. Select MD5('');  
  81. Select ENCODE(str,pswd_str) , DECODE(str,pp);  
  82. -- FORMAT(12321.223123,len)  
  83. -- 加密函数password(str)  
  84. -------------------------------  
  85. GET_LOCK('name',time);  IS_FREE_LOCK('name');   RELEASE_LOCK('name');  
  86. --加锁函数..        
  87. .
  88. >2014年5月29日22:01:13  .
  89. mysql 数据操作常用语句  
  90. CONCAT(IFNULL(a.blqingkuang,'0'),</span> 字符串连接,  DATE_FORMAT(ping_date,'%Y-%m') = DATE_FORMAT(CURDATE(),'%Y-%m') ";月份判断  
  91. DATEDIFF(ds.end_date,curdate())>= 0 时间差  
  92. int off = 0;
    String sql = "update wkrj_model_dcdb_s set ";
    if (dcdbs.getEnd_date() != null && dcdbs.getEnd_date() != "") {
    if (off == 0) {
    sql += " end_date ='" + dcdbs.getEnd_date() + "'";
    off++;
    } else {
    sql += ", end_date ='" + dcdbs.getEnd_date() + "'";
    }
    }
    if (dcdbs.getWork_station() != null && dcdbs.getWork_station() != "") {
    if (off == 0) {
    sql += " work_station ='" + dcdbs.getWork_station() + "'";
    off++;
    } else {
    sql += ", work_station ='" + dcdbs.getWork_station() + "'";
    }
    }
    if (dcdbs.getDept_work() != null && dcdbs.getDept_work() != "") {
    if (off == 0) {
    sql += " dept_work ='" + dcdbs.getDept_work() + "'";
    off++;
    } else {
    sql += ", dept_work ='" + dcdbs.getDept_work() + "'";
    }
    }
    if (dcdbs.getFg_yj() != null && dcdbs.getFg_yj() != "") {
    if (off == 0) {
    sql += " fg_yj ='" + dcdbs.getFg_yj() + "'";
    off++;
    } else {
    sql += ", fg_yj ='" + dcdbs.getFg_yj() + "'";
    }
    }

    sql+=" where dcdb_ids ='"+dcdbs.getDcdb_ids()+"'";
    int info = 0;
    System.out.println("sql-----------------"+sql);
    info = jdbcTemplate.update(sql);
    if (info > 0) {
    return true;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彳卸风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值