On 27 Dec 2003, at 21:04, daryl hansen wrote:


I can't find anything in the manual about proper syntax for this when creating a table. All I want is my "Price" field to equal the total of my "Adults" and "Children" fields. Can someone please draw me a picture?


CREATE TABLE Cart ( ID bigint (20) NOT NULL auto_increment , SessionID varchar (50) , Activity_ID varchar (5) , Company_ID varchar (5) , Submitted varchar (5) , Vendor varchar (50) , Activity varchar (50) , Adult_Label varchar (20) , Child_Label varchar (20) , Other_Label varchar (20) , Price_Adult varchar (10) , Price_Child varchar (10) , Price_Other varchar (10) , Price bigint (20) , Tax varchar (10) , Adults bigint (5) , Children bigint (5) , Other varchar (5) , Date date , CreateDate date , KEY `ID` (`ID`) )


Thanks,


Daryl Hansen


On Dec 26, 2003, at 11:54 PM, Steve Folly wrote:



On 27 Dec 2003, at 08:59, daryl hansen wrote:


How do I make "Field3" a calculation, which equals 2 if fields 1 & 2 where values set to "1"? Any pointers in the right direction would be sincerely appreciated.



Take a look at 6.3.1.3 and 6.3.1.4 in the MySQL documentation for logical operators and control flow functions.


HTH
Steve.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]





You can only use these functions from a select statement; not in a CREATE TABLE statement.


To be honest, there is (usually[1]) no point in having an extra column that is the always the result of some arithmetic expression involving other columns. It wastes space. You're better off calculating it in the query.

Steve.

[1] - I say 'usually' - I'm sure there are times when you would want to do this, perhaps caching lengthy calculations; but adding 2 numbers isn't! ;)




-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to