-2
表1:
Id | product | price
---+---------+------
1 | A | 5
1 | B | 3
1 | C | 6
表2:
Id | prod | subprod
---+------+--------
1 | A | xxxx
1 | A | yyyy
1 | A | zzzz
我的結果表應具有的所有3行從表2連同一個稱爲價格的新列(將從表1計算的值)
結果表應該像
Id|prod|subprod|price
--+----+-------+-----
1 | A | xxxx |(if subprod = xxxx in table 2 then this should have price of A from table 1)
1 | A | yyyy |(if subprod = yyyy in table 2, then if price of B is greater than price of C then the value should be price of B else 0)
1 | A | zzzz |(if subprod = zzzz in table 2, then if price of B is less than price of C then the value should be price of C-B else 0)
你想要整個if語句在你的輸出中,還是你想要if語句的解決方案?你到目前爲止還嘗試過什麼?發佈您的查詢 – RealCheeseLord
看起來像作業 –
@RealCheeseLord我創建了一個函數,所有這些硬編碼,並在查詢 – user2954417