S
S
Sekira2012-01-06 19:23:05
MySQL
Sekira, 2012-01-06 19:23:05

Temporary table in MySQL inside SELECT

There is a one-dimensional array of the form: key => value

A MySQL query is being executed: select `key`, `field` from `table` where `key` in (key1, key2, key3)
Then we run through the result:
result += array[key]*field
As a result, the desired number is in the “result” variable

Question:
Is it possible to somehow limit ourselves to one mysql query so that it already contains “result”, something like:
select sum(`table`.`field`*`temp`.`value`) from `table`, (key1 => value1, key2 => value2, key3 => value3) as `temp` where `key` in (key1, key2, key3) and `table`.`key`=`temp`.`key`

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Progrik, 2012-01-07
@Progrik

If MySQL 5 is installed, then the most correct thing to do and get the result is to write a stored procedure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question