各位大神有谁知道这个怎么实现

happy_girl_mu 2017-12-19 03:47:13
各位大神我需要通过SQL server2008R2实现图片上的效果,目前使用查询语句能具体的查出每一个季度的,就是不知道什么办法能把他们联立起来进行显示在一个表上,求大神指点!!!
...全文
244 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zbdzjx 2017-12-19
  • 打赏
  • 举报
回复
引用 2 楼 happy_girl_mu 的回复:
您好,这个是我查询的第三季度的数据,然后每个季度出的数据都是一样的,就是不知道怎么联。代码如下 select tab3.fname as 业务员,t3.fname as 类别,t4.FBudgeAmount as 任务, sum(t2 .FConsignAmount) as 完成,(sum(t2 .FConsignAmount)-t4.FBudgeAmount) as 差额, cast((sum(t2 .FConsignAmount)/t4.FBudgeAmount)*100 as varchar)+'%' as 完成率 from ICStockBill t1 inner join ICStockBillEntry t2 on t1.FInterID=t2.FInterID inner join t_Emp tab3 on tab3.FItemID=t1.FEmpID inner join t_Item_3002 t3 on t3.FItemID=t1.FHeadSelfB0163 inner join t_BM_SaleBudgetEntry t4 on t4.Fbase1=t3.FItemID inner join t_BM_SaleBudget t5 on t4.FID=t5.FID and t5.FEmpID=tab3.FItemID inner join t_BM_ProjectEntry t6 on t5.fprojectid=t6.FID inner join t_BM_Project t7 on t6.FID=t7.FID Where FTranType = 21 and t1.FStatus=1 and month(t1.fdate)>=7 and month(t1.fdate)<=9 and month(t6 .FBeginDate)>=7 and month(t6.FEndDate)<=9 group by t3.FName,t4.FBudgeAmount,tab3.fname
不怕麻烦和不考虑效率的情况下。 select * from (上面语句,去掉日期的判断) as t_all left join(上面的语句,日期判断为第一季度) as t_1 on t_all.业务员=t_1.业务员 and t_all.类别=t_1.类别 and t_all.任务=t_1.任务 left join(上面的语句,日期判断为第二季度) as t_2 on t_all.业务员=t_2.业务员 and t_all.类别=t_2.类别 and t_all.任务=t_2.任务 left join(上面的语句,日期判断为第三季度) as t_3 on t_all.业务员=t_3.业务员 and t_all.类别=t_3.类别 and t_all.任务=t_3.任务 left join(上面的语句,日期判断为第四季度) as t_4 on t_all.业务员=t_4.业务员 and t_all.类别=t_4.类别 and t_all.任务=t_4.任务
听雨停了 2017-12-19
  • 打赏
  • 举报
回复
引用 2 楼 happy_girl_mu 的回复:
您好,这个是我查询的第三季度的数据,然后每个季度出的数据都是一样的,就是不知道怎么联。代码如下 select tab3.fname as 业务员,t3.fname as 类别,t4.FBudgeAmount as 任务, sum(t2 .FConsignAmount) as 完成,(sum(t2 .FConsignAmount)-t4.FBudgeAmount) as 差额, cast((sum(t2 .FConsignAmount)/t4.FBudgeAmount)*100 as varchar)+'%' as 完成率 from ICStockBill t1 inner join ICStockBillEntry t2 on t1.FInterID=t2.FInterID inner join t_Emp tab3 on tab3.FItemID=t1.FEmpID inner join t_Item_3002 t3 on t3.FItemID=t1.FHeadSelfB0163 inner join t_BM_SaleBudgetEntry t4 on t4.Fbase1=t3.FItemID inner join t_BM_SaleBudget t5 on t4.FID=t5.FID and t5.FEmpID=tab3.FItemID inner join t_BM_ProjectEntry t6 on t5.fprojectid=t6.FID inner join t_BM_Project t7 on t6.FID=t7.FID Where FTranType = 21 and t1.FStatus=1 and month(t1.fdate)>=7 and month(t1.fdate)<=9 and month(t6 .FBeginDate)>=7 and month(t6.FEndDate)<=9 group by t3.FName,t4.FBudgeAmount,tab3.fname

--假设季度1的数据查询出来后插入临时表#tab1,季度2插入临时表#tab2中,下面这样关联就可以了啊
SELECT * FROM #tab1 a
INNER JOIN #tab2 b ON a.业务员=b.业务员 and a.类别=b.类别 and a.任务=b.任务
happy_girl_mu 2017-12-19
  • 打赏
  • 举报
回复
您好,这个是我查询的第三季度的数据,然后每个季度出的数据都是一样的,就是不知道怎么联。代码如下 select tab3.fname as 业务员,t3.fname as 类别,t4.FBudgeAmount as 任务, sum(t2 .FConsignAmount) as 完成,(sum(t2 .FConsignAmount)-t4.FBudgeAmount) as 差额, cast((sum(t2 .FConsignAmount)/t4.FBudgeAmount)*100 as varchar)+'%' as 完成率 from ICStockBill t1 inner join ICStockBillEntry t2 on t1.FInterID=t2.FInterID inner join t_Emp tab3 on tab3.FItemID=t1.FEmpID inner join t_Item_3002 t3 on t3.FItemID=t1.FHeadSelfB0163 inner join t_BM_SaleBudgetEntry t4 on t4.Fbase1=t3.FItemID inner join t_BM_SaleBudget t5 on t4.FID=t5.FID and t5.FEmpID=tab3.FItemID inner join t_BM_ProjectEntry t6 on t5.fprojectid=t6.FID inner join t_BM_Project t7 on t6.FID=t7.FID Where FTranType = 21 and t1.FStatus=1 and month(t1.fdate)>=7 and month(t1.fdate)<=9 and month(t6 .FBeginDate)>=7 and month(t6.FEndDate)<=9 group by t3.FName,t4.FBudgeAmount,tab3.fname
听雨停了 2017-12-19
  • 打赏
  • 举报
回复
如果要跟图片上的显示样式一模一样那是不可能,sql办不到的。你说的把多个季度合并显示的话,把每个季度查询的结果join一下就可以了啊。如果你不明白的话就把你的测试数据发出来,比如你查询出来的季度1 ,季度2的数据发一些出来,然后我做个简单的示范给你

34,588

社区成员

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

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