Is it possible to capture data from a WHERE clause?
I have a scenario where I'm calculating something in the WHERE
clause of my SQL, bu开发者_开发问答t I also want to get that calculation - since it's expensive. Is it possible to get the results of something done in the WHERE
clause, like this:
SELECT `foo` FROM `table` WHERE (foo = LongCalculation(`column`))
Wishful thinking, or possible with MySQL?
EDIT: Calculation is column dependent
set @bar = LongCalculation();
select foo from table where foo=@bar;
A bit of re-working @cherouvim's idea and I got it to work with row-dependent functions:
set @bar = 0;
SELECT
`product_name`,
@bar AS `stock`
FROM `jos_vm_product`
WHERE (@bar := `product_in_stock`) > 0
精彩评论