我得到了一个包含大量内容的表格和一个带有标志的列。有时我想加载所有内容,有时我不想加载 - 为了简化这个问题,我想仅根据标志加载内容。
有没有办法根据标志状态加载内容?
将表格想象成这样:
+--+--------------+-----+
|id|content |flag |
+--+--------------+-----+
| 0| lots of text |false|
| 1| lots of text |false|
| 2| lots of text | true|
+--+--------------+-----+
我希望我的结果集像这样填充:
+--+--------------+-----+
|id|content |flag |
+--+--------------+-----+
| 0| NULL |false| <- only content null, otherwise full row
| 1| NULL |false| <- only content null, otherwise full row
| 2| lots of text | true|
+--+--------------+-----+
SQL 查询是什么样的?这可能吗?
最佳答案
您可以使用其他人提到的 WHERE
或 IF
function ,例如:
SELECT t.id, IF(t.flag, t.content, NULL), t.flag from table t
关于java - 如果设置了标志,则 JDBC (My)SQL 仅获取单元格数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40494199/