### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: how to sum up values from three different table prices?  (Read 991 times)

#### Whillis

• New Member
• Posts: 10
##### how to sum up values from three different table prices?
« on: December 06, 2018, 02:31:02 am »
As i said in another topic, im a beginner with databases and this is actually something to test myself into making a database, its like a system for a shop, ill choose a type of Monitor, Computer case and keyboard (one of each) to make it into a full Pc showing the total price.

I got a database connected to lazarus with workbench, so far i got three tables (Monitor, Computer case and Keyboard)  each one with an id and a price, these three tables work into making another table (PC) that combines those 3 Id's, but now i want to also sum up the prices of the 3 components and make a total price in the PC table but i can't find how to code it out..

Ps. Im using Data controls (TDBGrids, TDBLLookupComboBoxes, etc) to show those tables data.
Error - 404

#### lucamar

• Hero Member
• Posts: 3025
##### Re: how to sum up values from three different table prices?
« Reply #1 on: December 06, 2018, 02:40:59 am »
While you're making the combined "PC" table, you can also get each price and sum them up to make a total. Save it with the combined Id, if you want. Doesn't sound very difficult, where are you finding problems? (And, what problems?)

ETA: The data controls matter very little in this context. What is really important are the data sources.
« Last Edit: December 06, 2018, 02:43:12 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

#### Whillis

• New Member
• Posts: 10
##### Re: how to sum up values from three different table prices?
« Reply #2 on: December 06, 2018, 03:37:51 am »
The components' Id's (monitor,keyboard. case...) will be in the table PC, which creates an Id for this group of id's setting an order   (something like: | pc_ID = M_id | C_id | K_id | ),

I didn't explained mysel very well but there's already 4 tables i made in workbench: Monitor/Computer case/Keyboard/PC, the issue is to make another column in the pc table with the total price of the 3 components (Monitor/C.Case/Keyboard),  now i dont know how it could be done in lazarus or already make a column 'Total Price' for the PC table in workbench and just set a code for summing up the values.
The problem is i dont really know how it would be done, i thought of making a button but i have no idea of what to code inside of it to call a total price value and place it into a total price .

basically i dont know how to put it into coding.
Error - 404

#### lucamar

• Hero Member
• Posts: 3025
##### Re: how to sum up values from three different table prices?
« Reply #3 on: December 06, 2018, 03:48:43 am »
Frankly speaking, this sounds like a very basic setup. There are lots of information on the wiki about databases, starting with the Database portal and the SQLdb Tutorial. You may want to read a little before starting to code. And google for a good SQL tutorial while you're at it
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

#### mangakissa

• Hero Member
• Posts: 1090
##### Re: how to sum up values from three different table prices?
« Reply #4 on: December 06, 2018, 08:42:59 am »
How do you store the founded records (Monitor/C.Case/Keyboard) in your application?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1