Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个像“table1”这样的表
NAME COL1 COL2 COL3 COL4 A 1 2 3 4
我想过滤表格
"SELECT * FROM table1 where (COL1=1 OR COL2=1 OR COL3=1 OR COL4=1)"
我希望结果是
NAME COL_NAME A COL1
可以通过 SQL 语句实现吗?
您不仅可以在选择列表中选择列,还可以使用表达式。例如,您可以使用这个:
SELECT NAME, -- More columns as needed CASE WHEN COL1=1 THEN 'COL1' WHEN COL2=1 THEN 'COL2' WHEN COL3=1 THEN 'COL3' WHEN COL4=1 THEN 'COL4' ELSE NULL END AS COL_MATCH FROM table1 where (COL1=1 OR COL2=1 OR COL3=1 OR COL4=1)