查看: 1048|回复: 5
|
SQL 的问题,看不懂!
[复制链接]
|
|
"select p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from p, pd, m left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
请问这两个是什么意思呢?那个db里没有NULL这个东东。
IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price
IF(s.status, s.specials_new_products_price, p.products_price) as final_price |
|
|
|
|
|
|
|
发表于 24-12-2005 04:00 PM
|
显示全部楼层
什么资料库?不同资料库有不同写法。
基本上, 类似的方法还有WHEN CASE |
|
|
|
|
|
|
|
发表于 24-12-2005 08:02 PM
|
显示全部楼层
原帖由 红发 于 24-12-2005 11:10 AM 发表
"select p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.pro ...
IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price
================================================================================
嗯。。。如果 s.status = true 的話。
那就把 s.specials_new_products_price 的數值當成 specials_new_products_price
再不然, specials_new_products_price = NULL |
|
|
|
|
|
|
|

楼主 |
发表于 27-12-2005 09:26 AM
|
显示全部楼层
还是有一点不明白。。。。。。。。。
那这个呢?
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
它是如何判断的呢???
又specials_new_products_price
又products_price 的?? |
|
|
|
|
|
|
|

楼主 |
发表于 28-12-2005 09:09 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 28-12-2005 09:38 AM
|
显示全部楼层
原帖由 红发 于 27-12-2005 09:26 AM 发表
还是有一点不明白。。。。。。。。。
那这个呢?
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
它是如何判断的呢???
又specials_new_products_price
又pro ...
拆开了, 就变成
IF (s.status = true)
final_price = s.specials_new_products_price
ELSE
final_price = p.products_price |
|
|
|
|
|
|
| |
本周最热论坛帖子
|