mysql在select语句的自动增长字段。

来源:互联网 发布:iphone微信数据慢 编辑:程序博客网 时间:2024/06/16 00:26

自己闲着弄的,写下来记录一下。

 

网上很多都是2个语句的。我自己想一个语句。测试后,在我的机器上运行成功。

 

 

首先是网上查到的。

 

select @a:=1

;

select @a:=@a+1 as rowid, invoiceid from invoices where invoiceid<1000 and price <20

 

 

 

我自己想一句写出来。不想分开语句。

select @a:=@a+1 as rowid, invoiceid from invoices where (select @a:=1) or (invoiceid<1000 and price <20)

 

 

我没有考虑过性能,因为我那个表是没有什么内容的。

原创粉丝点击