我有两张桌子,比如units
和price
。单位表字段是unit1
, unit2
。Price
表字段是id
, rateper
, price
. 现在我想像表一样连接这两个表Price
,rateper <=0
然后Price table is empty
返回 unit1
else rateper
。我写了如下查询,但没有工作
select case when rateper <=0 then unit1 else rateper from units,price
我正在使用postgresql
9.0 版
单位表
+------+-----+
|Unit1 |Unit2|
--------------
| 2 | 10 |
| 1 | 20 |
+------+------
价格表
+------+-------------+---------+
|id + rate per + price |
--------------------------------
|1 |0 | 100 |
|2 |1 | 200 |
|3 |2 | 300 |
--------------------------------
Result :
2
1
3
如果价格表没有行,则显示结果为
2
1