不懂求科普,我在做报表,我同事老让我用linq to sql 来写,能完成复杂的报表么。

好奇都是要学的 好奇都是要学的 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在的表报 基本都是好多表关了 在加上临时表组合成表报呈现在页面上,linq能很好的完成么比如下面的。我放的都是简单的表,还有跨表更多的。更麻烦的。
日营业统计报表
select CONVERT(varchar(100), a.DocDate, 23) Date,b.deptname , sum(a.Totalamt) SumPrice into #a from CusOrderM a
left join basdept b on a.deptno=b.deptno
where (a.paytype='1' or a.paytype='3') and iffree=0 and a.deptno='010101' and a.DocDate>='2016-04-16' and a.DocDate<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.DocDate, 23),b.deptname
select CONVERT(varchar(100), a.PlaceTime, 23) Date,b.deptname , sum(a.Price-isnull(c.TotalAmt,0)) SumPrice into #b from dbo.OrderReservation a
left join basdept b on a.deptno=b.deptno
left join CusOrderM c on a.OrderNo=c.DocNo
where (a.paytype='2' or a.paytype='4') and a.iffree=0 and a.deptno='010101' and a.PlaceTime>='2016-04-16' and a.PlaceTime<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.PlaceTime, 23),b.deptname
select CONVERT(varchar(100), a.DocDate, 23) Date,b.deptname , sum(a.Totalamt) SumPrice into #c from CusOrderM a
left join basdept b on a.deptno=b.deptno
where a.paytype='0' and iffree=0 and a.deptno='010101' and a.DocDate>='2016-04-16' and a.DocDate<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.DocDate, 23),b.deptname
select CONVERT(varchar(100), a.PlaceTime, 23) Date,b.deptname , sum(a.Price-isnull(c.TotalAmt,0)) SumPrice into #d from dbo.OrderReservation a
left join basdept b on a.deptno=b.deptno
left join CusOrderM c on a.OrderNo=c.DocNo
where a.paytype='0' and a.iffree=0 and a.deptno='010101' and a.PlaceTime>='2016-04-16' and a.PlaceTime<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.PlaceTime, 23),b.deptname
select CONVERT(varchar(100), a.Rechtime, 23) Date,b.deptname , sum(a.RechAmount) SumPrice into #e from RechargeRecord a
left join basdept b on a.deptno=b.deptno
where a.viptype='0' and a.deptno='010101' and a.Rechtime>='2016-04-16' and a.Rechtime<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.Rechtime, 23),b.deptname
select CONVERT(varchar(100), a.PlaceTime, 23) Date,b.deptname,sum(Price) SumPrice into #f from OrderReservation a
left join basdept b on a.deptno=b.deptno
where a.iffree='1' and a.deptno='010101' and a.PlaceTime>='2016-04-16' and a.PlaceTime<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.PlaceTime, 23),b.deptname
select CONVERT(varchar(100), a.DocDate, 23) Date,b.deptname , sum(a.Credit) SumPrice into #g from CusOrderM a
left join basdept b on a.deptno=b.deptno
where a.paytype='2' and iffree=0 and a.deptno='010101' and a.DocDate>='2016-04-16' and a.DocDate<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.DocDate, 23),b.deptname
select CONVERT(varchar(100), a.Rechtime, 23) Date,b.deptname , sum(a.RechAmount) SumPrice into #h from RechargeRecord a
left join basdept b on a.deptno=b.deptno
where a.viptype='1' and a.deptno='010101' and a.Rechtime>='2016-04-16' and a.Rechtime<'2016/4/17 0:00:00'
group by CONVERT(varchar(100), a.Rechtime, 23),b.deptname
select * into #date from (
select Date,deptname from #a
union
select Date,deptname from #b
union
select Date,deptname from #c
union
select Date,deptname from #d
union
select Date,deptname from #e
union
select Date,deptname from #f
union
select Date,deptname from #g
union
select Date,deptname from #h) date select a.Date '日期',a.deptname '门店',isnull(#a.SumPrice,0) '产品销售现金',isnull(#b.SumPrice,0)+isnull(#h.SumPrice,0) '服务销售现金',isnull(#c.SumPrice,0) '卡耗产品',isnull(#d.SumPrice,0) '卡耗服务',
isnull(#a.SumPrice,0)+isnull(#b.SumPrice,0)+isnull(#h.SumPrice,0)+isnull(#c.SumPrice,0)+isnull(#d.SumPrice,0) '营业合计',
#e.SumPrice '会员卡储值',
isnull(#a.SumPrice,0)+isnull(#b.SumPrice,0)+isnull(#e.SumPrice,0)+isnull(#h.SumPrice,0) '现金销售合计',
isnull(#c.SumPrice,0)+isnull(#d.SumPrice,0) '会员卡消耗合计',
#f.SumPrice '免单金额',#g.SumPrice '积分消费' from #date a
left join #a on a.date=#a.date
left join #b on a.date=#b.date
left join #c on a.date=#c.date
left join #d on a.date=#d.date
left join #e on a.date=#e.date
left join #f on a.date=#f.date
left join #g on a.date=#g.date
left join #h on a.date=#h.date
drop table #a
drop table #b
drop table #c
drop table #d
drop table #e
drop table #f
drop table #g
drop table #h
drop table #date

销售对账单
#NAME?
select * into #a from (
select StaffName,DocDate,deptname,sum(Price) Price from (
select a.CashierName StaffName,CONVERT(varchar(100),a.PlaceTime,23) DocDate, b.deptname ,sum(Price) Price from OrderReservation a
left join basdept b on a.deptno=b.deptno
where a.PayType='2' and a.PlaceTime>'2016-1-1' and a.PlaceTime<='2016-10-1' and iffree=0 and a.deptno='010101'
group by a.CashierName,CONVERT(varchar(100),a.PlaceTime,23),b.deptname
union all
select isnull(c.StaffName,'') StaffName, CONVERT(varchar(100),a.DocDate,23) DocDate,b.deptname ,sum(TotalAmt) Price from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
left join basstaff c on a.staffno=c.staffno
where a.PayType='3' and a.DocDate>'2016-1-1' and a.DocDate<='2016-10-1' and iffree=0 and a.deptno='010101'
and a.docno not in(select orderno from OrderReservation where a.docno=orderno)
group by c.StaffName,CONVERT(varchar(100),a.DocDate,23),b.deptname
union all
select isnull(c.StaffName,'') StaffName, CONVERT(varchar(100),a.Rechtime,23) DocDate,b.deptname ,sum(RechAmount) Price from dbo.RechargeRecord a
left join basdept b on a.deptno=b.deptno
left join basstaff c on a.staffno=c.staffno
where a.Rechtime>'2016-1-1' and a.Rechtime<='2016-10-1' and a.deptno='010101'
group by c.StaffName,CONVERT(varchar(100),a.Rechtime,23),b.deptname) a
group by StaffName,CONVERT(varchar(100),DocDate,23),deptname) a
#NAME?
select * into #b from (
select StaffName,DocDate,deptname,sum(Price) Price from (
select isnull(a.CashierName,'') StaffName,CONVERT(varchar(100),a.PlaceTime,23) DocDate, b.deptname ,sum(Price) Price from OrderReservation a
left join basdept b on a.deptno=b.deptno
where a.PayType='4' and a.PlaceTime>'2016-1-1' and a.PlaceTime<='2016-10-1' and iffree=0 and a.deptno='010101'
group by a.CashierName,CONVERT(varchar(100),a.PlaceTime,23),b.deptname
union all
select c.StaffName StaffName, CONVERT(varchar(100),a.DocDate,23) DocDate,b.deptname ,sum(TotalAmt) Price from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
left join basstaff c on a.staffno=c.staffno
where a.PayType='1' and a.DocDate>'2016-1-1' and a.DocDate<='2016-10-1' and iffree=0 and a.deptno='010101'
and a.docno not in(select orderno from OrderReservation where a.docno=orderno)
group by c.StaffName,CONVERT(varchar(100),a.DocDate,23),b.deptname
union all
select isnull(c.StaffName,'') StaffName, CONVERT(varchar(100),a.Rechtime,23) DocDate,b.deptname ,sum(RechAmount) Price from dbo.RechargeRecord a
left join basdept b on a.deptno=b.deptno
left join basstaff c on a.staffno=c.staffno
where a.Rechtime>'2016-4-6' and a.Rechtime<='2016-4-7' and a.deptno='010101' and a.PayType='网银'
group by c.StaffName,CONVERT(varchar(100),a.Rechtime,23),b.deptname)a
group by StaffName,CONVERT(varchar(100),DocDate,23),deptname) a
#NAME?
select * into #c from (
select a.CashierName StaffName,CONVERT(varchar(100),a.PlaceTime,23)DocDate, b.deptname ,sum(Price) Price from OrderReservation a
left join basdept b on a.deptno=b.deptno
where a.PlaceTime>'2016-1-1' and a.PlaceTime<='2016-10-1' and iffree=1 and a.deptno='010101'
group by a.CashierName,CONVERT(varchar(100),a.PlaceTime,23),b.deptname) a
#NAME?
select * into #d from (
select c.StaffName, CONVERT(varchar(100),a.DocDate,23) DocDate,b.deptname ,sum(TotalAmt) price from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
left join basstaff c on a.staffno=c.staffno
where a.PayType='2' and a.DocDate>'2016-1-1' and a.DocDate<='2016-10-1' and a.deptno='010101'
group by c.StaffName,CONVERT(varchar(100),a.DocDate,23),b.deptname) a
#NAME?
select * into #e from (
select StaffName,DocDate,deptname,sum(Price) Price from (
select a.CashierName StaffName,CONVERT(varchar(100),a.PlaceTime,23) DocDate, b.deptname ,sum(Price) Price from OrderReservation a
left join basdept b on a.deptno=b.deptno
where a.PayType='0' and a.PlaceTime>'2016-1-1' and a.PlaceTime<='2016-10-1' and iffree=0 and a.deptno='010101'
group by a.CashierName,CONVERT(varchar(100),a.PlaceTime,23),b.deptname
union all
select isnull(c.StaffName,'') StaffName, CONVERT(varchar(100),a.DocDate,23) DocDate,b.deptname ,sum(TotalAmt) Price from dbo.CusOrderM a
left join basdept b on a.deptno=b.deptno
left join basstaff c on a.staffno=c.staffno
where a.PayType='0' and a.DocDate>'2016-1-1' and a.DocDate<='2016-10-1' and iffree=0 and a.deptno='010101'
and a.docno not in(select orderno from OrderReservation where a.docno=orderno)
group by c.StaffName,CONVERT(varchar(100),a.DocDate,23),b.deptname) a
group by StaffName,CONVERT(varchar(100),DocDate,23),deptname) a
select * into #dept from (
select StaffName,DocDate,deptname from #a
union
select StaffName,DocDate,deptname from #b
union
select StaffName,DocDate,deptname from #c
union
select StaffName,DocDate,deptname from #d
union
select StaffName,DocDate,deptname from #e) a
select #dept.StaffName '收款员',#dept.DocDate '日期',#dept.deptname '收款门店' ,sum(#a.price) '现金',sum(#b.price) '银联卡',
sum(isnull(#a.price,0))+sum(isnull(#b.price,0)) '合计',sum(#e.Price) '会员卡消耗',sum(#c.Price) '免单',sum(#d.Price) '积分消费'
from #dept
left join #a on #dept.StaffName=#a.StaffName and #dept.DocDate=#a.DocDate and #dept.deptname=#a.deptname
left join #b on #dept.StaffName=#b.StaffName and #dept.DocDate=#b.DocDate and #dept.deptname=#b.deptname
left join #e on #dept.StaffName=#e.StaffName and #dept.DocDate=#e.DocDate and #dept.deptname=#e.deptname
left join #c on #dept.StaffName=#c.StaffName and #dept.DocDate=#c.DocDate and #dept.deptname=#c.deptname
left join #d on #dept.StaffName=#d.StaffName and #dept.DocDate=#d.DocDate and #dept.deptname=#d.deptname
group by #dept.StaffName,#dept.DocDate,#dept.deptname
drop table #a,#b,#c,#d, #e,#dept
...全文

相关推荐

电信运营基于分类模型的客户流失预警系统:数据挖掘驱动的精准挽留策略设计

内容概要:本文围绕电信客户流失预警与挽留策略,构建了一套从数据探索、预处理、特征工程、分类建模、模型评估与解释到业务落地的端到端数据挖掘实战方案。基于公开的 Telco Customer Churn 数据集,项目聚焦于识别高流失风险客户,并通过逻辑回归、随机森林和XGBoost等模型进行对比分析,结合ROC-AUC、精确率、召回率、F1等指标评估性能,利用SHAP等方法实现模型可解释性,最终将预测结果转化为可操作的客户分层与差异化挽留策略。文中强调了数据泄漏防范、类别不平衡处理、模型可复现性及A/B测试验证增量收益的重要性,并明确指出当前图表为示意性质,需通过附录代码运行真实数据生成结果。; 适合人群:具备一定数据分析与机器学习基础,从事数据科学、用户运营或客户留存相关工作的从业者,尤其是工作1-3年希望提升实战能力的研发与分析人员。; 使用场景及目标:①掌握客户流失预测的全流程方法论,包括数据清洗、特征工程、建模调参与模型解释;②学习如何将机器学习模型输出转化为可运营的客户触达策略;③理解模型评估与业务目标之间的衔接,如预算约束下的优先级排序与A/B测试设计; 阅读建议:此资源以实际业务场景驱动,不仅关注算法实现,更重视从业务定义到策略落地的闭环逻辑。建议结合附录提供的完整Python代码,在本地环境中下载数据集并复现分析流程,重点关注数据预处理防泄漏机制、模型管道构建、超参数调优策略及SHAP解释应用,避免将文中的示意图表误认为实测结果。

云博士的AI课堂

旋转高频信号注入法在PMSM零低速无位置控制中的仿真研究(Matlab代码实现)

内容概要:本文系统研究了旋转高频信号注入法在永磁同步电机(PMSM)零低速无位置传感器控制中的应用,并提供了基于Matlab/Simulink的完整仿真代码实现。针对PMSM在启动及低速运行时反电动势微弱导致传统观测器失效的问题,该方法通过在定子绕组中注入高频旋转电压信号,利用电机自身凸极效应产生的响应电流特征,实现对转子位置的高精度在线估计。文中详细阐述了该技术的理论基础、数学建模过程、仿真系统架构设计以及关键参数整定方法,全面验证了其在零速和低速工况下对转子初始位置辨识与动态跟踪的准确性、有效性及强鲁棒性。; 适合人群:具备电机控制理论基础知识和Matlab/Simulink仿真能力的电气工程、自动化、电力电子等相关专业的硕士研究生、博士研究生、科研人员以及从事高性能电机驱动系统研发的工程师。; 使用场景及目标:① 深入理解高频信号注入类无位置传感器控制技术的工作原理、信号处理机制与工程实现细节;② 掌握利用Matlab/Simulink搭建PMSM高性能矢量控制系统及高级观测器的仿真方法;③ 为开发高精度、低成本、全速度范围适用的PMSM无位置传感器驱动器提供坚实的理论依据和技术验证平台。; 阅读建议:建议读者结合文中详尽的理论推导与所提供的仿真代码进行对照学习,亲自动手运行、调试仿真模型,通过改变负载、转速、注入信号参数等工况,观察系统响应与控制效果的变化,从而深刻掌握旋转高频注入法的内在工作机制与设计要点。

威武编程狮

Python小Demo实例源码爬取网易云音乐评论

Python小Demo实例源码爬取网易云音乐评论

zz_ll9023one

Python3 finally执行铁律

finally代码块无论try内部是否报错、是否执行return,都会强制执行。唯一例外:调用os._exit()直接终止解释器,跳过finally。业务场景:数据库连接、网络套接字、文件句柄回收,放入finally保证资源释放。特殊细节:try内部return不会立刻返回,会先执行finally内部代码,再返回结果。新手易错:在finally内部写入return,会覆盖try原有返回值,导致业务数据异常,严禁在finally使用return语句。 tiyu.xastone.com www.yingjie168.com 17kuaibu.com www.0760yx.net 1900kk.com

2601_97221235

基于线性时变MPC的无人驾驶车辆双移线轨迹跟踪仿真研究(Matlab代码、Simulink仿真实现)

基于线性时变MPC的无人驾驶车辆双移线轨迹跟踪仿真研究(Matlab代码、Simulink仿真实现)

稷下科研社
评论 8
收藏 已收藏
分享
返回顶部