怎么把这些语句拼起来啊

caoyang0299 2011-06-16 06:04:17
select '缩合' , '78#' , fdecimal as 一月 from t_BOS200002318,t_BOS200002318entry
where t_BOS200002318.fid=t_BOS200002318entry.fid and t_BOS200002318.fcombobox4='1月'

select fdecimal4 as 二月 from t_BOS200002318,t_BOS200002318entry
where t_BOS200002318.fid=t_BOS200002318entry.fid and t_BOS200002318.fcombobox4='2月'

select fdecimal4 as 三月 from t_BOS200002318,t_BOS200002318entry
where t_BOS200002318.fid=t_BOS200002318entry.fid and t_BOS200002318.fcombobox4='3月'
...全文
62 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
FlySQL 2011-06-16
  • 打赏
  • 举报
回复
select 
[缩合],
[78#],
sum(case when [fcombobox4]='1月' then fdecimal else 0 end) as [一月],
sum(case when [fcombobox4]='2月' then fdecimal else 0 end) as [二月],
sum(case when [fcombobox4]='3月' then fdecimal else 0 end) as [三月],
sum(case when [fcombobox4]='4月' then fdecimal else 0 end) as [四月],
sum(case when [fcombobox4]='5月' then fdecimal else 0 end) as [五月],
sum(case when [fcombobox4]='6月' then fdecimal else 0 end) as [六月],
sum(case when [fcombobox4]='7月' then fdecimal else 0 end) as [七月],
sum(case when [fcombobox4]='8月' then fdecimal else 0 end) as [八月],
sum(case when [fcombobox4]='9月' then fdecimal else 0 end) as [九月],
sum(case when [fcombobox4]='10月' then fdecimal else 0 end) as [十月],
sum(case when [fcombobox4]='11月' then fdecimal else 0 end) as [十一月],
sum(case when [fcombobox4]='12月' then fdecimal else 0 end) as [十二月]
from
[t_BOS200002318] a
join
[t_BOS200002318entry] b
on
a.fid=b.fid
group by
[缩合],[78#]
caoyang0299 2011-06-16
  • 打赏
  • 举报
回复
第一个select 结果
缩合,78#,一月
55
第二个 二月
44
最终结果
缩合 78# 一月 二月 三月 四月……
55 44 33 22
--小F-- 2011-06-16
  • 打赏
  • 举报
回复
需要得到什么结果??给个例子看看
叶子 2011-06-16
  • 打赏
  • 举报
回复

select '缩合' , '78#' , fdecimal as 一月 from t_BOS200002318,t_BOS200002318entry
where t_BOS200002318.fid=t_BOS200002318entry.fid and t_BOS200002318.fcombobox4='1月'
union all
select fdecimal4 as 二月 from t_BOS200002318,t_BOS200002318entry
where t_BOS200002318.fid=t_BOS200002318entry.fid and t_BOS200002318.fcombobox4='2月'
union all
select fdecimal4 as 三月 from t_BOS200002318,t_BOS200002318entry
where t_BOS200002318.fid=t_BOS200002318entry.fid and t_BOS200002318.fcombobox4='3月'

是这个意思?
caoyang0299 2011-06-16
  • 打赏
  • 举报
回复
具体点呗,谢谢诶
jinjazz 2011-06-16
  • 打赏
  • 举报
回复
case when行列转换

34,594

社区成员

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

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