好的,这有点棘手,但基本上在我的SQL语句中我比较每行中字段之间的价格以获得返回的最低值,现在的问题是每个值都有一个链接。
是否有办法根据SQL语句中的最低值返回正确的链接?
下面是我的SQL语句。
SELECT
title,
my_value,
my_ink,
LEAST(site_a_value, site_b_value, site_c_value) AS lowest_value,
site_a_link,
site_b_link,
site_c_link
FROM STOCK
因此,例如,如果site_b具有最低值,我只希望返回site_b_link。
答案 0 :(得分:4)
尝试
SELECT title,
my_value,
my_ink,
LEAST(site_a_value, site_b_value, site_c_value) AS lowest_value,
case LEAST(site_a_value, site_b_value, site_c_value)
when site_a_value then site_a_link
when site_b_value then site_b_link
when site_c_value then site_c_link end AS lowest_value_link,
FROM STOCK
答案 1 :(得分:1)
试试这个:
SELECT
title, my_value, my_ink,
LEAST(site_a_value, site_b_value, site_c_value) AS lowest_value,
(
CASE site_a_value = LEAST(site_a_value, site_b_value, site_c_value)
THEN site_a_link
ELSE CASE site_b_value = LEAST(site_a_value, site_b_value, site_c_value)
THEN site_b_link
ELSE
site_c_link
) AS site_link
FROM STOCK