mysql 数据库unsigned的用法

  1. 在mysql数据库中,unsigned表面含义是 '无符号’的意思,unsigned既为非负数,用此类型可以增加数据长度.
    例如,如果 int最大是2147683647,那 tint unsigned 最大 就可以到 2147683647 * 2

  2. 与unsigned类似的还有binary,unsigned 属性只针对整型,而binary属性只用于char 和varchar。

  3. 当设置为unsigned时候,报错BIGINT UNSIGNED value is out of range…如何解决
    使用unsigned限制数值范围为正数的时候,如果执行相减操作产生负数;就会报错;解决方法
    核心: 使用 cast(targetCol as signed) 将所有涉及到的unsigned字段先转化为signed类型后,再进行运算

-- 需要添加四个计算值计算每日变化数据
-- dayConfirmed: 每日确诊
-- dayRecovered: 每日康复
-- dayDeaths: 每日死亡
-- dayExisting: 当日现存
select n.id,
       n.region_id,
       n.region_parent_id,
       n.recovered,
       n.deaths,
       n.day_date,
       n.confirmed,
       (cast(n.confirmed as signed) - cast(m.confirmed as signed)) as dayConfirmed,
       (cast(n.recovered as signed) - cast(m.recovered as signed)) as dayRecovered,
       (cast(n.deaths as signed) - cast(m.deaths as signed))       as dayDeaths,
       (cast(n.confirmed  as signed) - cast(n.recovered  as signed) - cast(n.deaths  as signed))    as dayExisting
from region_data_total as n
         join region_data_total as m on date_sub(n.day_date, interval 1 day) = m.day_date
where n.region_id = m.region_id and n.day_date = (select max(day_date) from region_data_total);
  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值