简体   繁体   中英

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.

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. You must use WHERE...OR... for selecting all things that have been done on car.

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. This query is based on understanding of ID_Service in that it means id whitch is common for all repairs done on one car.

Bit unclear question. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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