sqlserver支持top關(guān)鍵字,返回前100條數(shù)據(jù)。select top 100 * from table;// 返回前100行數(shù)據(jù)
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比長(zhǎng)順網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式長(zhǎng)順網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋長(zhǎng)順地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。
mysql支持limit,一個(gè)參數(shù):select * from table limit 100; //返回前100行記錄
Oracle需要使用rownum。select * from table where rownum=100; //返回前100條數(shù)據(jù)
TOP 子句
TOP 子句用于規(guī)定要返回的記錄的數(shù)目。
對(duì)于擁有數(shù)千條記錄的大型表來(lái)說(shuō),TOP 子句是非常有用。
SQL Server 的語(yǔ)法:
SELECT TOP number|percent column_name(s)
FROM table_name
limit子句用于強(qiáng)制select語(yǔ)句返回置頂?shù)挠涗洈?shù),參數(shù)必須是整數(shù)常量。一個(gè)參數(shù)是返回前幾條記錄;兩個(gè)參數(shù)時(shí),第一個(gè)參數(shù)指定第一個(gè)返回記錄行的偏移量(初始記錄行的偏移量是0),第二個(gè)參數(shù)指定返回記錄的最大數(shù)目。
添加listbox1,label1,command1
Public Class Form1
Dim N(10) As Integer
'生成隨機(jī)數(shù)
Private Sub CreatRand()
Dim I As Integer
Dim Strarr As String
Strarr = ""
ListBox1.Items.Clear()
Dim R As New System.Random
For I = 0 To 9
N(I) = R.Next(30, 100)
ListBox1.Items.Add(Str(N(I)))
Strarr = Strarr Str(N(I)) " "
Next
'添加標(biāo)簽的橫向數(shù)字序列
Label1.Text = Strarr
End Sub
'獲取最大值
Private Function GetMax() As Integer
Dim I As Integer
Dim intMax As Integer
intMax = 0
For I = 0 To 9
intMax = IIf(intMax N(I), intMax, N(I))
Next
Return intMax
End Function
'獲取最小值
Private Function GetMin() As Integer
Dim I As Integer
Dim intMin As Integer
intMin = 101
For I = 0 To 9
intMin = IIf(intMin N(I), intMin, N(I))
Next
Return intMin
End Function
'獲取平均值
Private Function GetAve() As Single
Dim I As Integer
Dim Sum As Integer
Sum = 0
For I = 0 To 9
Sum = Sum + N(I)
Next
Return Sum / 10
End Function
'生成隨機(jī)數(shù),顯示各種值
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call CreatRand()
MsgBox("最大值=" Str(GetMax()) ",最小值=" Str(GetMin()) ",平均值=" Str(GetAve()))
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j
j = GetRndNotRepeat(1, 10, 10)
If j(0) Then
For i = 1 To 10
MsgBox(j(i))
Next
End If
End Sub
Public Function GetRndNotRepeat(ByVal NumMin As Integer, ByVal NumMax As Integer, ByVal n As Integer)
'編制:xsfhlzh
'功能:取NumMin到NumMax間的n個(gè)隨機(jī)整數(shù)
'說(shuō)明:取數(shù)標(biāo)志數(shù)組是Byte,每一位表示NumMin到NumMax間某個(gè)數(shù)的狀態(tài)
Dim arr() As Integer
If n NumMax - NumMin + 1 Then
ReDim arr(0)
arr(0) = 0
Return arr
Else
ReDim arr(n)
Dim m As Integer
Dim b() As Byte
m = Int((NumMax - NumMin) / 8)
ReDim b(m)
'取數(shù)標(biāo)志
Dim i
Dim x, y, z As Integer
Randomize()
arr(0) = 1
For i = 1 To n
Do
'找到x的位置,y表示x在數(shù)組的第幾個(gè)字節(jié),z表示x在該字節(jié)的第幾位
x = Int(Rnd() * (NumMax - NumMin + 1)) + NumMin
y = x - NumMin
z = 2 ^ (y Mod 8)
y = y \ 8
Loop While b(y) And z
b(y) = b(y) Or z
arr(i) = x
'找到未取的數(shù),并放入數(shù)組,設(shè)置標(biāo)志位
Next i
End If
Return arr
End Function