關於如何用sql語句查詢出連續的一串數字

2022-03-29 23:21:55 字數 507 閱讀 7425

在資料庫操作中,經常有一些這樣的操作:插入諾幹條測試資料、查詢這個月的登入情況(沒有登入的日期不能不存在,要顯示數量為0),獲取諾幹條guid。

這些的基礎都是怎麼生成連續的一串數字  1 2  3  4  ……………… 100000。

在oracle中,我們使用start with  connect by

select rownum from dual start with rownum = 1 connect by rownum <= 100000

在sqlserver中,由於沒有現成的語法,我們可以採用cte

with test as

(

select1rn

union all

select test.rn + 1 rn from test where test.rn <= 100000

)select rn from test

關於語法部分這裡就不詳細解釋了,相關文件鋪天蓋地。

如何用SQL語句進行模糊查詢?

like條件一般用在指定搜尋某字段的時候,通過 萬用字元的作用實現模糊查詢功能,萬用字元可以在前面也可以在後面或前後都有。搜尋以mian開頭 select from teble where title like mian 搜尋以mian結束 select from teble where title...

如何用SQL語句查詢Excel資料?

q 如何用sql語句查詢excel資料?a 下列語句可在sql server中查詢excel工作表中的資料。excel 2007和2010版本 select from opendatasource microsoft.ace.oledb.12.0 data source c book1.xlsx u...

如何用SQL語句查詢Excel資料?

如何用sql語句查詢excel資料?q 如何用sql語句查詢excel資料?a 下列語句可在sql server中查詢excel工作表中的資料。2007和2010版本 select from opendatasource microsoft.ace.oledb.12.0 data source c ...