Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > dbase calculations
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 2nd September 20:00
kalles
External User
 
Posts: 1
Default dbase calculations



Hello

I'm rather new when it comes to databases and I was hoping that someone
could help me out! I was just wondering is it possible to make a field in
MySQL dbase wich is a total of two other fields.

ie.

field_XX is a sum of field_1 and field2

Thanks

-Kalle


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw
  Reply With Quote


 


2 15th September 16:30
ajackman
External User
 
Posts: 1
Default dbase calculations



Kalle,
The usual way to do this is to create the table with the 2 real fields
and then use a query to 'create' the sum field at run time. For example
assume you have this table:

create table my_table (
field_1 int(9),
field_2 int(9)
);

then you can write this query:
SELECT field_1, field_2, (field_1 + field_2) AS my_sum FROM my_table;

This print 3 'fields', the third one is called my_sum and contains the
sum of the other two (the AS keyword gives a field a name).

Hope this helps,
Andy.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw
  Reply With Quote


 


Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666