建立記錄
--create table t(id numeric,class varchar(50))
--delete t
declare @i numeric
set @i=0
while @i<5000
begin
set @i=@i+1
insert into t(id,class) values(@i,'a')
endwhile @i<10000
begin
set @i=@i+1
insert into t(id,class) values(@i,'b')
endwhile @i<15000
begin
set @i=@i+1
insert into t(id,class) values(@i,'c')
end用時0:00:06
取六條記錄
方法一select a.* from t a
where a.id in (select top 2 id from t where class = a.class order by id)
用時0:02:10
方法二select * from t a
where (select count(1) from t where class=a.class and id<=a.id) between 1 and 2
用時0:00:30
按某一欄位取無重複記錄sql語句
測試資料 id name ic address 1 張三一 1234 bj 2 張三二 1234 bj 3 李四 12345 bj 4 李四 12345 bj 期望結果 id name ic address 2 張三二 1234 bj 4 李四 12345 bj 說明 按照ic取無重複的記錄,相同i...
mysql按某一欄位分組取最大 小 值所在行的資料
mysql技巧 按某一欄位分組取最大 小 值所在行的資料,這是mysql資料庫 程式設計師經常用到的在處理一些報表資料時候可以活用!那麼獵微網 將總結幾種mysql查詢最大值 mysql查詢最小值的方法!mysql表圖如下 具體php 連線mysql資料庫php 我就不寫 下面看select怎麼查詢...
arcpy批量更新shp某一欄位的值
提取檔名更新到dlbh欄位 encoding utf 8 import csv import arcpy import os shuju r d short2.gdb wenjianjia r d desktop csv.gdb fish r d desktop yw fishnet.shp res...
排序之根據某一欄位的應用排序實現
ds裡介紹了各種狂拽酷炫的排序演算法,但是都是基於單個元素,實際應用中對某條記錄的某個欄位來排序的情況層出不窮,如果還是原來的演算法直接用的話,恐怕無濟於事,於是我想怎麼根據某個欄位來排序,當時學c 的時候qsort,一直都用這個排序,有個compare函式比較糾結,裡面指標多,這個是排序的依據,在...
對二維陣列的某一欄位求和
方法一 array sum array map create function val return val size arr 方法二 array sum array map function val arr 對於windows系統,這兩種方法均可用。對於linux系統,只有方法一可用,如果是方法二...