我数据库表中有一列 里面有为空、有为数字、有字符,现在我想统计只是数字的总合怎么做。进来学习一下~! select count(1) from ta where isnumeric(col) = 1 用isnumeric 不是很厚道吧?
select sum(case when isnumeric(col) = 1 then col else 0 end) from tb 可以将 isnumeric() 函数重写 参考: http://hi.csdn.net/link.php?url=http://blog.csdn.net%2FliangCK
让后再 select sum(列) from tb where 重写后的isnumeric=1 SQL code: ---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2009-12-24 16:13:52 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([col] varchar(3)) insert [tb] select 'a' union all select '12' union all s