當前位置:首頁 » 編程語言 » sql行數

sql行數

發布時間: 2022-01-12 20:45:33

sql 以行數分組

使用ntile實現
select sum(num) num from
( select ntile(2) over ( order by id ) n_id ,* from 表 ) a
group by n_id

select sum(num) num from
( select ntile(3) over ( order by id ) n_id ,* from 表 ) a
group by n_id

⑵ 如何用SQL語句查詢表名和行數

//查詢所有表明
select name from sysobjects where xtype='u'

select * from sys.tables

//查詢資料庫中所有的表名及行數

SELECT a.name, b.rows

FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id

WHERE (a.type = 'u') AND (b.indid IN (0, 1))

ORDER BY a.name,b.rows DESC

//查詢所有的標明及空間佔用量\行數

select

object_name(id) tablename,

8*reserved/1024 reserved,

rtrim(8*dpages)+'kb' used,

8*(reserved-dpages)/1024 unused,

8*dpages/1024-rows/1024*minlen/1024 free,

rows

--,*

from sysindexes

where indid=1

order by tablename,reserved desc

⑶ sql語句查詢*每行*的行數

行號,是指在一定順序的記錄中排列的名次數。

在SQL中,如果沒有排序,記錄順序是不一定的,

所以,也就不能確定行號(這叫已知條件不足吧)。

但是您如果告訴了要按什麼順序排列,就可以很簡單地求出行號。

比如按您給出的兩列COL1,COL2排序,就可以這樣求行號:
SELECT 行號=(select count(1) from tablename a where a.col1*10000+a.col2<=tablename.col1*10000+tablename.col2),* from tablename order by col1,col2

⑷ SQL 返回行數問題

你只要行數嗎,在外面加一層查詢;


selectcount(*)cnt
from(selectReasonDes,GateAction,AntennaNo,MAX(RecordDate)fromTBL_BarrierGateRecord
whereDateDiff(hh,RecordDate,getDate())<=168
andGateId=01groupbyReasonDes,GateAction,AntennaNoHavingGateAction=0andAntennaNo=304
)aaa

⑸ sql 查詢某個庫中的每個表的記錄行數

最簡單的是這個:
select a.name as '表名',b.rows as '表數據行數'
from sysobjects a inner join sysindexes b
on a.id = b.id
where a.type = 'u'
and b.indid in (0,1)
order by b.rows desc
親測OK。

⑹ sql查詢語句如何添加一個統計數據行數

具體看你什麼資料庫了,還有你欄位1,欄位2,欄位3哪個欄位是字元類型的。

比如欄位3是字元類型:

oracle寫法:

SELECT欄位1,欄位2,欄位3FROM列印數據表where列印時間>='2018-09-01'AND列印時間<'2018-09-19'
unionall
selectnull,null,'合計:'||count(*)from列印數據表where列印時間>='2018-09-01'AND列印時間<'2018-09-19'

mysql寫法:

SELECT欄位1,欄位2,欄位3FROM列印數據表where列印時間>='2018-09-01'AND列印時間<'2018-09-19'
unionall
selectnull,null,concat('合計:',(cast(count(*)asvarchar)from列印數據表where列印時間>='2018-09-01'AND列印時間<'2018-09-19'

sqlserver寫法:

SELECT欄位1,欄位2,欄位3FROM列印數據表where列印時間>='2018-09-01'AND列印時間<'2018-09-19'
unionall
selectnull,null,'合計:'+(cast(count(*)asvarchar)from列印數據表where列印時間>='2018-09-01'AND列印時間<'2018-09-19'

⑺ 如何快速獲得SQL Server 錶行數

其實有兩個辦法可以快速的查詢到SQL Server的表數據。1. sp_spaceused:其中有一列是rows,如果輸入的表對象的話,那麼就會獲得這個表的行數,速度非常快。其中也有一個列為rowcnt,Counts the total number of inserted, deleted, or updated rows since the last time statistics were updated for the table 使用下面的語句:---replace the tablename when you use this script from sys.sysindexes where id =object_id('tablename') and indid in(0,1) 通過這個統計結果可能不是太准確,因為系統統計信息有個時間差

⑻ SQL表查詢最大行數

只需要將你查詢出數據的sql將select
...
from
的內容改為
select
count(*)
from
就能得到查詢的最大記錄數了

熱點內容
玩qq三國要什麼樣的電腦配置 發布:2024-09-20 00:50:57 瀏覽:445
樹莓派zero編譯驅動 發布:2024-09-20 00:50:56 瀏覽:483
上傳文件文件夾找不到 發布:2024-09-20 00:26:32 瀏覽:915
承台箍筋加密區 發布:2024-09-20 00:26:31 瀏覽:228
筆記本什麼配置能流暢運行cf 發布:2024-09-20 00:14:19 瀏覽:952
實測華為編譯器 發布:2024-09-19 23:50:52 瀏覽:822
linux匯總 發布:2024-09-19 23:46:39 瀏覽:453
阿里雲伺服器環境搭建教程 發布:2024-09-19 23:21:58 瀏覽:837
黃色文件夾圖標 發布:2024-09-19 23:19:22 瀏覽:684
mysql資料庫導出導入 發布:2024-09-19 23:00:47 瀏覽:183