Visual FoxPro 查询添加总计
我有以下简单查询,它只是对 1 行或多行进行求和。基于独特的参考。
我想要做的是将总计列添加到按 JobRef 分组的 jobcharge.nAccrInv 的结果中,
即
Job_Ref / Name / Sales / Total
123 / VAT / 10.0
123 / DUTY / 10.0
123 / GHC / 10.0 / 30.0
SELECT DISTINCT ;
Job.cJobRef AS JobRef,;
Job.cName AS Customer_Name, ;
Job.cJobType AS JobType, ;
Job.cJobMode AS JobMode, ;
Job.cOrigin AS Org,;
Job.cDestination AS Dest,;
Job.cOwner AS Owner,;
jobcharge.cInvoiceDescr as [Invoice_Desc], ;
jobcharge.nAccrInv as [Accrued_Costs], ;
jobcharge.nCostInv as [Actual_Costs], ;
jobcharge.nSaleInv as [Sales], ;
( SELECT SUM(jobcharge.nAccrInv) AS SalesTotals FROM jobcharge WHERE NJOBID =3524); FROM job;INNER JOIN jobcharge ON job.nJob_Id = jobcharge.nJobId; WHERE job.cJobRef= "RSJC00001" AND job.cOwner = 'DBQ'
谢谢罗斯
I have the follwoing simple query which just SUMS the total of 1 or more rows. Based on a unique reference.
What I want to do is add a total column to the results of the jobcharge.nAccrInv grouped by JobRef
I.e
Job_Ref / Name / Sales / Total
123 / VAT / 10.0
123 / DUTY / 10.0
123 / GHC / 10.0 / 30.0
SELECT DISTINCT ;
Job.cJobRef AS JobRef,;
Job.cName AS Customer_Name, ;
Job.cJobType AS JobType, ;
Job.cJobMode AS JobMode, ;
Job.cOrigin AS Org,;
Job.cDestination AS Dest,;
Job.cOwner AS Owner,;
jobcharge.cInvoiceDescr as [Invoice_Desc], ;
jobcharge.nAccrInv as [Accrued_Costs], ;
jobcharge.nCostInv as [Actual_Costs], ;
jobcharge.nSaleInv as [Sales], ;
( SELECT SUM(jobcharge.nAccrInv) AS SalesTotals FROM jobcharge WHERE NJOBID =3524); FROM job;INNER JOIN jobcharge ON job.nJob_Id = jobcharge.nJobId; WHERE job.cJobRef= "RSJC00001" AND job.cOwner = 'DBQ'
Thanks Ross
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(太多了,无法放入评论字段)...稍后会回答。
您的 nJobID = 3524 的目的是什么,您只对一份工作感兴趣吗?如果是这样,您的查询将仅提供作业 3525 的总数,无论从 JOB 的 WHERE 子句返回的所有作业如何。
我将处理查询,但您不需要 DISTINCT。
此外,您只有 jobCharge.nArrcInv、.nCostInv、.nSaleInv,但后来您使用 SUM( jobcharge.nAccrInv )...您的意图是获取应计成本总和、实际成本总和、每个工作的销售额总和描述???包括其他作业标题内容吗?
看起来您想要每种工作活动类型的各个子组总数以及整个工作中所有销售额的总计...也许您想要的是这个...
实际上我已经给了您更多的列在每一行上显示每个职位描述的总计,以及与整个职位相比的总计(应计、实际和销售额)。您始终可以忽略您不关心的列,但这为您提供了我认为您想要的内容的方法。
此外,我假设最后一个连接到“JOB”表(因为未提供),其主键列只是“nID”而不是“nJob_ID”(作为 jobCharge 表的外键)。
如果您希望这些结果涵盖整个作业集,我实际上只需从 JobCharge 查询中删除相应的“WHERE”子句即可。
(Too much to put into a comment field)... will answer later.
What is the purpose of your nJobID = 3524, are you only interested in one job? If so, your query will give you the total only for job 3525 regardless of all the jobs returned from the JOB's WHERE clause.
I'll work on the query, but you do not want DISTINCT.
Additionally, you have just the jobCharge.nArrcInv, .nCostInv, .nSaleInv, but later you use SUM( jobcharge.nAccrInv )... Is your INTENT to get a sum of accrued costs, sum of actual costs, sum of sales per job description??? inclusive of other job header content?
It looks like you want both individual sub-group totals per type of job activity PLUS the grand total of all sales across the entire job... maybe what you want is this...
I've actually given you a few more columns to show on an every row, its Totals per job description, AND, the TOTALS compared to the entire job (for accrued, actual and sales). You can always ignore the columns you don't care about, but this gives you a how to of what I think you want.
In addition, the last join to the "JOB" table I am assuming (since not provided), its primary key column is just "nID" instead of "nJob_ID" (as foreign key to the jobCharge table).
If you wanted these results spanning an entire set of jobs, I would actually just remove the respective "WHERE" clauses from the JobCharge queries.