首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一SQL语句~解决方法

2012-01-14 
求一SQL语句~有一表结构如下:idname--------------12111212121312141215121612171218要求选出最后一位能被

求一SQL语句~
有一表结构如下:

idname
--------------
1211
1212
1213
1214
1215
1216
1217
1218


要求选出最后一位能被3除后余0的记录:

1213
1216

[解决办法]
select id from table whrere cast(right(id,1) as int)%3=0?
[解决办法]
select id from tb where (right(convert(char(4),id),1)%3)=0
[解决办法]
可以
select id from #temp where cast(right(id,1) as int)%3=0

----
1213
1216



[解决办法]
create table T(id int)
insert T select 1211
union all select 1212
union all select 1213
union all select 1214
union all select 1215
union all select 1216
union all select 1217
union all select 1218

select * from T
where right(rtrim(id), 1)%3=0

--result
id
-----------
1213
1216

(2 row(s) affected)

热点排行