select top 2 Tab.a from table1 order by Tab.a 或 select top 2 Tab.a from table1 order by Tab.a desc
什么规律? 你要说出规律才可以。where a in (2.1111,3.1111)
什么意思啊? select top 2 * from Tab??select * from Tab where a=2.1111 or a=3.1111??
Table:TabA姓名 性别 分数 a 男 82.4 b 男 80 c 女 92.4 e 男 0 .....有10几万条记录,现在要对分数进行四舍五入工作--小数点后的不要了,为了提高速度 本来是整数的过滤掉,如80,0等select * from TabA where 分数....? ----如何实现?!
-------------------------------------------------------- --****************************************************-- --*************** CREATE TABLE ***********************-- -------------------------------------------------------- create table test2(name varchar(20),sex varchar(2),scores numeric(5,2))-------------------------------------------------------- --****************************************************-- --****************** INSERT DATA *********************-- --------------------------------------------------------SET TEXTSIZE 0 -- Create variables for the character string and for the current -- position in the string. DECLARE @position int, @string char(26) -- Initialize the current position and the string variables. SET @position = 14 SET @string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' WHILE @position <= DATALENGTH(@string) BEGIN SELECT ASCII(SUBSTRING(@string, @position, 2)), CHAR(ASCII(SUBSTRING(@string, @position, 2))) INSERT INTO TEST2(NAME,SEX,SCORES)VALUES( CHAR(ASCII(SUBSTRING(@string, @position, 1))),'女',@POSITION*0.4+60) SET @position = @position + 1 END GOSET TEXTSIZE 0 -- Create variables for the character string and for the current -- position in the string. DECLARE @position int, @string char(26) -- Initialize the current position and the string variables. SET @position = 1 SET @string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' WHILE @position <= DATALENGTH(@string)*0.5 BEGIN SELECT ASCII(SUBSTRING(@string, @position, 2)), CHAR(ASCII(SUBSTRING(@string, @position, 2))) INSERT INTO TEST2(NAME,SEX,SCORES)VALUES( CHAR(ASCII(SUBSTRING(@string, @position, 1))),'男',@POSITION*0.4+60)
SET @position = @position + 1 END GO -------------------------------------------------------- --****************************************************-- --**************** RESULT **************************-- --------------------------------------------------------select name,sex ,(case when cha>=0.5 then cha2 else cha1 end) from (select name,sex,cha1=ceiling(scores),cha2=floor(scores),cha=ceiling(scores)-scores from test2) b select * from test2-------------------------------------------------------- --****************************************************-- --****************************************************-- -------------------------------------------------------- /*测试结果 name sex -------------------- ---- ------- N 女 66 O 女 66 P 女 66 Q 女 67 R 女 67 S 女 68 T 女 68 U 女 68 V 女 69 W 女 69 X 女 70 Y 女 70 Z 女 70 A 男 60 B 男 61 C 男 61 D 男 62 E 男 62 F 男 62 G 男 63 H 男 63 I 男 64 J 男 64 K 男 64 L 男 65 M 男 65 */ -------------------------------------------------------- --****************************************************-- --****************************************************-- --------------------------------------------------------
select * from taba where round(分数,0) - 分数 > 0
select * from taba where round(分数,0)*1.00 - 分数 > 0
或
select top 2 Tab.a from table1 order by Tab.a desc
你要说出规律才可以。where a in (2.1111,3.1111)
select top 2 * from Tab??select * from Tab where a=2.1111 or a=3.1111??
a 男 82.4
b 男 80
c 女 92.4
e 男 0
.....有10几万条记录,现在要对分数进行四舍五入工作--小数点后的不要了,为了提高速度
本来是整数的过滤掉,如80,0等select * from TabA where 分数....?
----如何实现?!
--------------------------------------------------------
--****************************************************--
--*************** CREATE TABLE ***********************--
--------------------------------------------------------
create table test2(name varchar(20),sex varchar(2),scores numeric(5,2))--------------------------------------------------------
--****************************************************--
--****************** INSERT DATA *********************--
--------------------------------------------------------SET TEXTSIZE 0
-- Create variables for the character string and for the current
-- position in the string.
DECLARE @position int, @string char(26)
-- Initialize the current position and the string variables.
SET @position = 14
SET @string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT ASCII(SUBSTRING(@string, @position, 2)),
CHAR(ASCII(SUBSTRING(@string, @position, 2)))
INSERT INTO TEST2(NAME,SEX,SCORES)VALUES( CHAR(ASCII(SUBSTRING(@string, @position, 1))),'女',@POSITION*0.4+60) SET @position = @position + 1
END
GOSET TEXTSIZE 0
-- Create variables for the character string and for the current
-- position in the string.
DECLARE @position int, @string char(26)
-- Initialize the current position and the string variables.
SET @position = 1
SET @string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
WHILE @position <= DATALENGTH(@string)*0.5
BEGIN
SELECT ASCII(SUBSTRING(@string, @position, 2)),
CHAR(ASCII(SUBSTRING(@string, @position, 2)))
INSERT INTO TEST2(NAME,SEX,SCORES)VALUES( CHAR(ASCII(SUBSTRING(@string, @position, 1))),'男',@POSITION*0.4+60)
SET @position = @position + 1
END
GO
--------------------------------------------------------
--****************************************************--
--**************** RESULT **************************--
--------------------------------------------------------select name,sex
,(case when cha>=0.5 then cha2 else cha1 end)
from (select name,sex,cha1=ceiling(scores),cha2=floor(scores),cha=ceiling(scores)-scores from test2) b
select * from test2--------------------------------------------------------
--****************************************************--
--****************************************************--
--------------------------------------------------------
/*测试结果
name sex
-------------------- ---- -------
N 女 66
O 女 66
P 女 66
Q 女 67
R 女 67
S 女 68
T 女 68
U 女 68
V 女 69
W 女 69
X 女 70
Y 女 70
Z 女 70
A 男 60
B 男 61
C 男 61
D 男 62
E 男 62
F 男 62
G 男 63
H 男 63
I 男 64
J 男 64
K 男 64
L 男 65
M 男 65
*/
--------------------------------------------------------
--****************************************************--
--****************************************************--
--------------------------------------------------------