取整函数和浮点计算函数,判断奇偶数,mysql序列号

  • 取整函数
- 取整函数
round(x) 表示该值四舍五入 无小数位
round(x,d) 表示x值四舍五入,d位小数
floor(x) 向下取整 返回整数 小数舍弃  floor(7/2) =3 
ceiling(x) 向上取整 返回整数 ceiling(7/2)=4 
mod(x,y) 取余数 select mod(3,2) 
- 判断奇偶数 select if(mod(5,2)>=1,'奇数','偶数')
  • 序列号
- 排序列号
select @rownum := @rownum + 1 as rank,
table.* 
from (select @rownum := 0) r ,F0126 tblae
- 分组序号
SELECT
    @r:= case when @type=a.company then @r+1 else 1 end as rownum,
    @type:=a.company  as company,
    a.id as id,
		a.salary as salary
from 
    F0126 a ,(select @r:=0 ,@type:='') b  
select * from (SELECT
    @r:= case when @type=a.company then @r+1 else 1 end as rownum,
    @type:=a.company  as company,
    a.id as id,
		a.salary as salary
from 
    F0126 a ,(select @r:=0 ,@type:='') b  )t where rownum in(
select n from (
select t.count,t.expr,if(t.expr = '奇数',ceiling(t.count/2),floor(t.count/2)) as n from (select count(1)as count,if(mod(count(1),2)>=1,'奇数','偶数')as expr from (SELECT
    @r:= case when @type=a.company then @r+1 else 1 end as rownum,
    @type:=a.company  as company,
    a.id as id,
		a.salary as salary
from 
    F0126 a ,(select @r:=0 ,@type:='') b  )t 
group by company)t)t)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值