Sqlite

除特定值外,選擇行並將兩列合併為一

  • April 5, 2022

我有一個三列表

CREATE TABLE "colls" (
   "w1"    TEXT,
   "w2"    TEXT,
   "coocc_freq"    INTEGER
)

我只想獲得具有 s 值的 w1 和 w2:

SELECT * FROM colls where w1='s' or w2='s' order by coocc_freq desc

我怎樣才能只保留兩列?w1 + w2 - s= w

即我想跳過s價值並得到類似的東西:

SELECT COALESCE(NULLIF(w1, 's'), w2) AS w
      coocc_freq
FROM colls 
WHERE 's' IN (w1, w2);

引用自:https://dba.stackexchange.com/questions/310572