DELIMITER //
CREATE PROCEDURE GetItems()
BEGIN
SELECT @total := count(id) FROM items
SET @sql = CONCAT('SELECT id, title FROM items LIMIT 0,', CEIL(@toal/2))
PREPARE stmt FROM @sql
EXECUTE stmt
END //
DELIMITER
希望这个思路对你有帮助,可以将limit后面设置为变量!
select * from phone where phonenumber regexp '[[:digit:]]$'试试看
抱歉,题目没看清楚。。
刚查了下mysql的正则表达式文档,不支持back reference,所以我只能想到用最笨的方法做
select *
from phone where
substring(phonenumber,-1,1) = substring(phonenumber,-2,1) and substring(phonenumber,-3,1) = substring(phonenumber,-4,1) and substring(phonenumber,-1,1) = substring(phonenumber,-4,1)
postgresql数据库的正则支持back reference。。
如果id是自增的话:
select DISTINCT l1.num from tab l1,tab l2, tab l3where
l1.id = l2.id -1 and
l1.id = l3.id -2 and
l1.num = l2.num and
l1.num = l3.num
2.id不连续
select distinct Numfrom (
select Num,
case
when @prev = Num then @count := @count + 1
when (@prev := Num) is not null then @count := 1
end as CNT
from tab, (select @prev := null,@count := null) as t
) as temp
where temp.CNT >= 3
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)