怎么在sql中数据后面加上%

pengpeng409 2011-10-15 03:34:10
select
a01.a01ho '标准岗',
C21.C211I '业务类别',
sum(C21.C210R+C21.C2110+C21.JBGZ)/sum(C21.C2131) '固定工资',
sum( C21.C210P)/sum(C21.C2131) '绩效工资',
sum(C21.C212H+C21.C212B)/sum(C21.C2131) '奖金/提成',
(sum(isnull(C21.C212M,0)
+isnull(C21.C212P,0)
+isnull(C21.C212Q,0)
+isnull(C21.C212R,0)
+isnull(C21.C212S,0)
+isnull(C21.C212T,0)
+isnull(C21.C212U,0)
+isnull(C21.C212V,0)
+isnull(C21.C212W,0)
+isnull(C21.C212X,0)
+isnull(C21.C212Y,0)
+isnull(C21.C210X,0)
+isnull(C21.C210Y,0)
+ isnull(C21.C212L,0)+ isnull(C21.C2108,0)+isnull(C21.C210X,0)-isnull(C21.C211Z,0)))/sum(C21.C2131) '补贴类',
sum(C21.C2115+C21.C211R)/sum(C21.C2131)'保险类',
sum(C21.C2131) '人工成本合计'
from C21,a01
where 1=1
and gz_ym='201108'
--and c21.a0191='在职人员'
and C21.C211K ='宿迁'
and
(a01.a0188 in (select a0188 from a01)
or
( C21.C211K ='宿迁' and
todept in (select dept_id from deptcode where dept_code like '125%')))
and a01.a0188=c21.a0188
group by a01.a01ho,C21.C211I
...全文
1611 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2011-10-17
  • 打赏
  • 举报
回复
用cast/convert

rtrim/ltrim
把數字轉為字符再加上'%'
twmickle 2011-10-17
  • 打赏
  • 举报
回复
楼主的原始sql没有哪句需要加百分比的输出啊?是不是贴错了
pengpeng409 2011-10-17
  • 打赏
  • 举报
回复
125 是部门编码啊...不是数字
pengpeng409 2011-10-17
  • 打赏
  • 举报
回复
呵呵。。。牛人。。。。
wcj1018_net 2011-10-15
  • 打赏
  • 举报
回复
select dept_id from deptcode where dept_code like '125%'
wanglingzhong 2011-10-15
  • 打赏
  • 举报
回复
呃,想回答问题还顺便做个阅读理解题

ltrim可以这样用,学习了
叶子 2011-10-15
  • 打赏
  • 举报
回复

declare @t table (col1 int,col2 int)
insert into @t
select 2,3 union all
select 1,4 union all
select 3,6

select
col1,
col2,
百分比=
ltrim(cast(cast(col1 as decimal(18,2))*100/cast(col2 as decimal(18,2))
as decimal(18,2)))+'%' from @t
/*
col1 col2 百分比
----------- ----------- ------------------------------------------
2 3 66.67%
1 4 25.00%
3 6 50.00%
*/
--小F-- 2011-10-15
  • 打赏
  • 举报
回复
ltrim(cast(sum(C21.C2115+C21.C211R)*100.0/sum(C21.C2131) as dec(18,2))+'%'
菜花 2011-10-15
  • 打赏
  • 举报
回复
没法子优化一下么 这样写写就容易写错吧
dawugui 2011-10-15
  • 打赏
  • 举报
回复
where dept_code like '125%'

这么写没错.
CalvinR 2011-10-15
  • 打赏
  • 举报
回复
偶也木有看懂啊
qgqch2008 2011-10-15
  • 打赏
  • 举报
回复
沒有語法錯誤,報什麽錯誤么?
唐诗三百首 2011-10-15
  • 打赏
  • 举报
回复
看不太懂,望楼主明示为宜.

dongzeqwq 2011-10-15
  • 打赏
  • 举报
回复
select dept_id from deptcode where dept_code like '125%'
意思是 类似于125XXXX
xxxx随意长度随意数值 不推荐 百分号加在前面..影响速度

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧