进来看,这个用sql怎么实现???

可不可以用select实现选取一个字段的后四位,单独输出一列?目的是要对这四位进行比较,最后把所有相同的记录汇总求和!
谢谢指点!^_^
---------------------------------------------------------------

Try:

select *,right(field1,4) from tablename where ...

select right(field1,4) as x,sum(field2) as field2 from tablename where ...
group by right(field1,4)

select right(rtrim(field1),4) as x,sum(field2) as field2 from tablename where ...
group by right(rtrim(field1),4)

---------------------------------------------------------------

不知具体情况,看不出有什么可优化的。对它们建索引试试:
txmd_rktj.cpbh,ymj.txmd_pbsjy.pbbh
---------------------------------------------------------------

给视图建个索引!对表建索引可能用途不大

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus