| View previous topic :: View next topic |
| Author |
Message |
hwoehrle General User

Joined: 21 Sep 2009 Posts: 14 Location: Germany, Ulm
|
Posted: Thu Feb 18, 2010 2:52 am Post subject: [SOLVED] Calculate with Alias / calculated Fields |
|
|
Hi,
is there a way to use calculated fields in the same query for further calculation?
For example, i need to do some calculation on areas and process them further. My area-calculation looks like:
| Code: |
IFNULL(
CASEWHEN( "Massbezug" = 'a', ( ( "Breite_a" * "Laenge_a" ) + "Flaeche_a" ), (
CASEWHEN( "Massbezug" = 'm', ( ( "Breite_m" * "Laenge_m" ) + "Flaeche_m" ), (
CASEWHEN( "Massbezug" = 'i', ( ( "Breite_i" * "Laenge_i" ) + "Flaeche_i" ), 0 ) ) ) ) ) * "Anzahl_n"*"Faktor", "Anzahl_n"*"Faktor" ) AS "Flaeche_Schicht"
|
This area i need for six other calculated fields. Is there any elegant way other than repeate the area-calculation in each of them?
Best regards,
heiko
Last edited by hwoehrle on Mon May 17, 2010 11:31 pm; edited 1 time in total |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 Location: 3rd Rock From The Sun
|
Posted: Thu Feb 18, 2010 8:36 am Post subject: |
|
|
If I am understanding your question and what you are trying to do correctly, if it were me ( famous last words ) . . . what I would do is create a View.
A View, in a database, is 'treated' just like a table, but, it contains no data. Rather, it tells the database what data to retrieve. In this case, you can define the calculation for "Flaeche_Schicht" once, if you include the Primary Key in the View. That is, your view would have two fields ( assuming your Primary Key is made up of one field ):- The Primary Key Field(s)
- The calculation for "Flaeche_Schicht"
Now that you have 'one' calculation for "Flaeche_Schicht", whenever you wanted the "Flaeche_Schicht" again, for example in a Query, just include your original table, AND the View, linked by the Primary Key.
Note: To create a View , after opening your database, click on Tables on the left, and, Create View...
I hope this helps, please be sure to let me / us know.
Sliderule
Thanks to add [Solved] in your first post title ( edit button ) if your issue has been fixed / resolved. |
|
| Back to top |
|
 |
hwoehrle General User

Joined: 21 Sep 2009 Posts: 14 Location: Germany, Ulm
|
Posted: Mon May 17, 2010 11:32 pm Post subject: Thanks! |
|
|
Many thanks to sliderule for saving my day once again!  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|