MSSQL2000取整,判断列内容是否唯一
1\列数值型取整数,不需进行四舍五入
表名:TEST2
列名:quantity
0.8
1.8
30.259
0.003
122323
要求结果
列名:quantity
0
1
30
0
122323
2\列名TNT
如何判断该列的内容是否唯一,唯一时返回T,否则为F
------解决方案--------------------
- SQL code
SELECT FLOOR([quantity]) FROM [tb]
------解决方案--------------------
select distinct 列名 from 表名
select count(*) from 表名
看看记录数是否相等
------解决方案--------------------
select cast([quantity] as int) from 表名
------解决方案--------------------
- SQL code
--> 测试数据:[tb]IF OBJECT_ID('[tb]') IS NOT NULL DROP TABLE [tb]GO CREATE TABLE [tb]([quantity] NUMERIC(9,3))INSERT [tb]SELECT 0.8 UNION ALLSELECT 1.8 UNION ALLSELECT 30.259 UNION ALLSELECT 0.003 UNION ALLSELECT 122323--------------开始查询-------------------------- SELECT b.[quantity],CASE WHEN b.cnt>1 THEN 'F' ELSE 'T' END FROM [tb] a LEFT JOIN( SELECT FLOOR([quantity]) AS [quantity],COUNT(*) AS cnt FROM [tb] GROUP BY FLOOR([quantity]) ) b ON FLOOR(a.[quantity]) =b.[quantity] ----------------结果----------------------------/* quantity --------------------------------------- ----0 F1 T30 T0 F122323 T(5 行受影响)*/
------解决方案--------------------
- SQL code
SELECT CASE COUNT(1) WHEN 1 THEN 'TRUE' ELSE 'FALSE' END AS count FROM tbaGROUP BY TNT