Quote:
Can a field in the database hold a function,


Not quite "hold" a function but yes, the MySQL engine can perform rudimentary (and not so rudimentary) calculations. In our game, what we would normally make an inline function
--
Code:
inline distance(x,y,z){ return)sqrt(x^2+y^2+z^2););} 

--
we calculate by making a call to the MySQL engine via the A6/7 plugin. An example from our code:
--

Code:
 
//Set the distance of SOI People
i = 0;
while (i < num_rows)
{
str_cpy(sql_cmd, "update soi set distance = ");
	str_cat(sql_cmd, "sqrt(pow((select pos_x from position where handle = '");
	str_cat(sql_cmd, send_handles.string[i]);
	str_cat_num(sql_cmd, "') - %f, 2)) + ", cur_pos[0]); 
						
	str_cat(sql_cmd, "sqrt(pow((select pos_y from position where handle = '");
	str_cat(sql_cmd, send_handles.string[i]);
	str_cat_num(sql_cmd, "') - %f, 2)) + ", cur_pos[1]); 
						
	str_cat(sql_cmd, "sqrt(pow((select pos_z from position where handle = '");
	str_cat(sql_cmd, send_handles.string[i]);
	str_cat_num(sql_cmd, "') - %f, 2)) ", cur_pos[2]); 
						
	[...]



For you, something like this might be useful or at least set you in the right direction:

Code:
"SELECT type, SUM(price) FROM products GROUP BY type";