mysql在select語句的自動增長字段。

2021-08-25 20:04:47 字數 364 閱讀 5927

自己閒著弄的,寫下來記錄一下。

網上很多都是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)

我沒有考慮過效能,因為我那個表是沒有什麼內容的。

mysql的select語句中in的用法是什麼

在mysql中,select語句內in常用於where表示式中,其作用是查詢某個範圍內的資料,in查詢的範圍資料並不一定是明確的,可能會包含子查詢語句,語法為 select from where.in 範圍資料或者子查詢語句 本教程操作環境 windows10系統 mysql8.0.22版本 del...

MySQL筆記4 SELECT語句

為了使用select檢索表資料,必須至少給出兩條資訊 想選擇什麼,以及從什麼地方選擇。輸入 select prod name from products 分析 上述語句利用select 語句從products 表中檢索乙個名為prod name的列。所需的列名在select關鍵字之後給出,from關...

SELECT 語句 MySQL檢索常見用法

學習 from 子句 select column from list name column 為所檢索列的名字,list name 為列所在的表select column1,column2,column3 from list name column1,column2 為所檢索列的名字萬用字元 可用於...