首先建立一个表如下: ======================= BirthDay datetime not null Age 通过公式计算得出 ======================= 以上是表的两个字段,通过BirthDay字段的数据自动生成Age字段 Age字段的公式如下: (case when (datediff(year,[BirthDay],getdate()) <> 0) then (ltrim(datediff(year,[BirthDay],getdate()))
select a.*,b.item_name from (select sum(buy_num) num,nqh from (select substr(a.embed_dis_province,1,10) dtime,b.buy_num,case substr(a.idcardcode,1,2) when '11' then '1100' when '12' then '1200' when '31' then '3100' when '50' then '5000' else substr(
IdentityNumber 是身份证号 年龄: ,), GETDATE()) / 365.25) as '推荐人年龄', 15位的身份证计算年龄: case when b.IdentityNumber IS null or b.IdentityNumber='' then '' ,), )) ,), )) else '' end as '推荐人年龄', 性别: ,) ) ) ) then '男' ,) ) ) ) then '女' else '' end as '推荐人性别',