mysql 中用sql判断两个字段长度是否相等

mysql 中用sql判断两个字段长度是否相等,第1张

create function myLength(@col varchar(1000)) returns int

as

begin

declare @v int

set @v=1

declare @i int

set @i=charindex('|',@col)

while(@i>0)

begin

set @v=@v+1

set @col=substring(@col,@i+1,len(@col))

set @i=charindex('|',@col)

end

return @v

end

go

select dbo.mylength('123') //结果是1

select dbo.mylength('|123') //结果是2

select dbo.mylength('|123|') //结果是3

你的语句就可以用:

select * from 表 where dbo.mylength(a) <>dbo.mylength(b)

--注意函数名前要加dbo.

你的记录集里只有2条呀,除了李四,或者也可以这样写

select * from t_user where name not in ('李四')

这样也可以查除了name是李四的总条数

select COUNT(*) from t_user where name not in ('李四')


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7281423.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存