简体   繁体   English

如何添加SUM列(在数据网格视图中)以汇总来自其他数据表的数据?

[英]How to add column of SUM (in data grid view) to sum data from releation of other data table?

Ok so I have two tables. 好的,所以我有两个桌子。

First one is "Service" which contains information about Car, date, employee working on car, and so on. 第一个是“服务”,其中包含有关汽车,日期,在汽车上工作的员工等信息。

2nd table is "service journal". 第二个表是“服务日志”。 It contains this: 它包含以下内容:

ID ID_Service Text Price

1 1 blabla 50

2 1 gfdgfd 75

Both tables have they own data grid view. 这两个表都有自己的数据网格视图。

I want to add column "Sum" at first datagrid, which shows sum of all prices. 我想在第一个数据网格中添加列“总和”,该列显示所有价格的总和。 For this example it would be 75. 对于此示例为75。

How can I do that? 我怎样才能做到这一点?

If "Service journal" means "price list", try to write this query: 如果“服务日记”表示“价格清单”,请尝试编写以下查询:

SELECT ..., SUM([Price]) FROM xyz WHERE ID_Service=x OR ID_Service=y

And than use Eval in column settings and than you'll have generated new column whitch will be named as "Columnx" where x equals index of column in query. 然后,在列设置中使用Eval,然后将生成新的列变量,将其命名为“ Columnx”,其中x等于查询中列的索引。 You must use WHERE...OR... for selecting all things that have been done on car. 您必须使用WHERE ... OR ...来选择在车上完成的所有事情。

Or if "Service journal" means list of all repairs done on all cars whitch have ever been done in service, try to write this query: 或者,如果“服务日志”表示在使用中对所有汽车进行的所有维修的列表,请尝试编写以下查询:

SELECT ..., SUM([Price]) FROM Service_journal WHERE ID_Service=CarServiceNumber

This SQL query will get summary of prices of all services/repairs whitch have been done. 此SQL查询将获取已完成的所有服务/维修的价格摘要。 This query is based on understanding of ID_Service in that it means id whitch is common for all repairs done on one car. 该查询基于对ID_Service的理解,这意味着id抽动对于一辆汽车上的所有维修都是常见的。

Bit unclear question. 有点不清楚的问题。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM