根据身份证判断男女的规则:二代身份证为18位,判断倒数第二位,第二位若为奇数,性别为男:偶数则为女 一代身份证为15为,判断倒数第一位,规则同上. update 表名 set 表名.字段名= case when substring(表名,身份证字段,17,1)%2=1 and length(表名.身份证字段) =18 then "男" when substring(表名,身份证字段,17,1)%2=0 and length(表名.身份证字段) =18 then "女"
原表 sql语句: SELECT ) ' then '北京市' ' then '天津市' ' then '河北省' ' then '山西省' ' then '内蒙古自治区' ' then '辽宁省' ' then '吉林省' ' then '黑龙江省' ' then '上海市' ' then '江苏省' ' then '浙江省' ' then '安徽省' ' then '福建省' ' then '江西省' ' then '山东省' ' then '河南省' ' then '湖北省' ' then
SELECT t.card_number ,) AS "省份", SUBSTR(t.card_number,,) "出生年月", SUBSTR(t.card_number,,) "性别" , CASE (SUBSTR(t.card_number,,)%) WHEN THEN '男' WHEN THEN '女' END AS '性别' FROM user t ;
sql语句判断方法之一CASE语句用法总结 背景: Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜索函数 CASE WHEN sex = '1' THEN '男' WHEN sex = '2' THEN '女' ELSE '其他' END 这两种方式,可以实现相同的功能.简单Case函数的写法相对比较简洁,但是和Case搜索函数相
1. sql语句判断是否为数字.字母.中文 select ascii(字段) 数字:48-57字母:65-123汉字:123+ 如,要删除某个全为数字的字段 DELETE FROM table WHERE ascii(name) between 48 and 57 2. 一.包含中文字符 select * from 表名 where 列名 like '%[吖-座]%' 二.包含英文字符 select * from 表名 where 列名 like '%[a-z]%' 三.包含纯数字 selec
sql语句判断方法之一 selectcase when t.bk1='on' then 1else 0 end as 基础 ,case when t.bk2='on' then 1else 0 end as 法规 ,case when t.bk3='on' then 1else 0 end as 电算化 from info t select t.bk1,t.bk2,t.bk3,case when t.bk1='on' then 1else 0 end +case when t.bk2='
from master..sysdatabases where name='TestDB') print 'TestDB存在'else print 'TestDB不存在' --判断表[TestTb]是否存在if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb')) print '表TestTb存在'else print '表TestTb不存在' --判断[TestD
TFlowCreateTask--表名 AddDate--字段名 if not exists( select d.name from syscolumns a join sysobjects b on a.id=b.id join syscomments c on a.cdefault=c.id join sysobjects d on c.id=d.id where b.name='TFlowCreateTask' and (a.name='AddDate') ) ALTER TABLE [d
方法一 select * from AAA where to_char(a,'yyyymmdd') = to_char(sysdate,'yyyymmdd'); select * from AAA where to_char(a,'yyyymmdd') = to_char(sysdate-1,'yyyymmdd'); 方法二 select * from AAA where trunc(a) = trunc(sysdate); select * from AAA where trunc(a)
MySQL数据库-条件语句.循环语句.动态执行SQL语句 1.if条件语句 delimiter \\ CREATE PROCEDURE proc_if () BEGIN ; THEN ; ELSEIF i THEN ; ELSE ; END IF; END\\ delimiter ; 2.循环语句 while循环 delimiter \\ CREATE PROCEDURE proc_while () BEGIN DECLARE num INT ; ; DO SELECT num ; ; END