本文主要給大家介紹實(shí)現(xiàn)sqlserver的row_number函數(shù)方法,其所涉及的東西,從理論知識(shí)來(lái)獲悉,有很多書(shū)籍、文獻(xiàn)可供大家參考,從現(xiàn)實(shí)意義角度出發(fā),創(chuàng)新互聯(lián)累計(jì)多年的實(shí)踐經(jīng)驗(yàn)可分享給大家。
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比夏縣網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式夏縣網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋夏縣地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
1. 使用臨時(shí)表
CREATE DEFINER=`root`@`%` PROCEDURE `sp_getMonitorInfo`(IN d_itemId INT, IN d_configId INT, d_count_num INT )
begin
set @count = 0;
set @num = 0;
SELECT @count :=count(1) FROM better.MonitorInfo where itemId=d_itemId and configId=d_configId;
IF @count<300
THEN
SELECT id,cpu,cpu1,cpu2,cpu3,diskRead,diskWrite,memory,networkReceive,networkSend,time,configId,itemId FROM MonitorInfo where itemId=itemId and configId=configId;
ELSE
SET @num= round(@count/d_count_num,0);
select @num;
create temporary table tmp_MonitorInfo
(
tmp_id int(4) primary key not null auto_increment,
id int(4) not null,
cpu int,
cpu1 int,
cpu2 int,
cpu3 int,
diskRead int,
diskWrite int,
memory int,
networkReceive int,
networkSend int,
time varchar(40),
configId int,
itemId int
);
insert into tmp_MonitorInfo(id,cpu,cpu1,cpu2,cpu3,diskRead,diskWrite,memory,networkReceive,networkSend,time,configId,itemId)
select id,cpu,cpu1,cpu2,cpu3,diskRead,diskWrite,memory,networkReceive,networkSend,time,configId,itemId from MonitorInfo
where itemId=d_itemId and configId=d_configId;
select id,cpu,cpu1,cpu2,cpu3,diskRead,diskWrite,memory,networkReceive,networkSend,time,configId,itemId from tmp_MonitorInfo
where tmp_id%@num=0;
drop table tmp_MonitorInfo;
END IF;
end
2. 使用臨時(shí)變量
CREATE DEFINER=`root`@`%` PROCEDURE `sp_getMonitorInfo_2`(IN d_itemId INT, IN d_configId INT, d_count_num INT )
begin
set @count = 0;
set @num = 0;
SELECT @count :=count(1) FROM better.MonitorInfo where itemId=d_itemId and configId=d_configId;
IF @count<300
THEN
SELECT id,cpu,cpu1,cpu2,cpu3,diskRead,diskWrite,memory,networkReceive,networkSend,time,configId,itemId FROM MonitorInfo where itemId=itemId and configId=configId;
ELSE
SET @num= round(@count/d_count_num,0);
select @num;
set @i = 0;
select * from (
select @i :=@i + 1 as tmp_id,id,cpu,cpu1,cpu2,cpu3,diskRead,diskWrite,memory,networkReceive,networkSend,time,configId,itemId from MonitorInfo
where itemId=d_itemId and configId=d_configId) aa
where aa.tmp_id%@num=0;
END IF;
看了以上介紹實(shí)現(xiàn)sqlserver的row_number函數(shù)方法,希望能給大家在實(shí)際運(yùn)用中帶來(lái)一定的幫助。本文由于篇幅有限,難免會(huì)有不足和需要補(bǔ)充的地方,大家可以繼續(xù)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊板塊,會(huì)定期給大家更新行業(yè)新聞和知識(shí),如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時(shí)售前售后,隨時(shí)幫您解答問(wèn)題的。
標(biāo)題名稱:實(shí)現(xiàn)sqlserver的row_number函數(shù)方法
當(dāng)前路徑:http://jinyejixie.com/article30/ppppso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、自適應(yīng)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、靜態(tài)網(wǎng)站、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)