Issue
I want to apply some customised mathematics formula on values present in the database !..Directly In The Database..! but I don't know how to do it.
Solution
If you can express your formulas using MySql built in math functions you can put them in SELECT statements.
SELECT x, y, SQRT(x*x, y*y) dist FROM mytable
is a simple example.
You can declare a generated column in a table.
ALTER TABLE mytable
ADD COLUMN dist DOUBLE AS SQRT( x*x + y*y);
Then SELECT x, y, dist FROM mytable gives you the computed result.
You can create views of tables using SELECT statements with formulas in them.
CREATE OR REPLACE VIEW myComputedView AS
SELECT x, y, SQRT(x*x, y*y) dist FROM mytable
Then SELECT x, y, dist FROM myComputedView gives your result.
You didn't tell us much about your problem, so it's hard to recommend one of these techniques over the others.
Beware: in scaled-up applications, the database server is a scarce resource. It's often best to put complex calculations elsewhere in your system, in client or web server code.
Answered By - O. Jones
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.