开发者

Is it possible to capture data from a WHERE clause?

开发者 https://www.devze.com 2023-01-03 19:30 出处:网络
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 s

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 
0

精彩评论

暂无评论...
验证码 换一张
取 消