1

と のような 2 つのテーブルがunitsありpriceます。単位テーブルのフィールドはunit1unit2です。Priceテーブル フィールドはid、、、rateperですprice。今、テーブルのようにこれらの2つのテーブルを接続するPricerateper <=0、elsePrice table is emptyを返し ます。以下のようなクエリを書きましたが、うまくいきませんunit1rateper

 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

Price テーブルに行がない場合は、結果が表示されます

2
1
4

1 に答える 1