💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# mysql语句部分 # \# MySQL中,not in子查询 ``` <pre class="calibre13">``` select <span class="token5">ID</span> <span class="token2">as</span> id<span class="token1">,</span> <span class="token5">TYPE_CODE</span> <span class="token2">as</span> typeCode <span class="token1">,</span> <span class="token5">TYPE_NAME</span> <span class="token2">as</span> typeName <span class="token1">,</span> <span class="token5">PARENT_ID</span> <span class="token2">as</span> parentsId <span class="token1">,</span> <span class="token5">STYLE</span> <span class="token2">as</span> style <span class="token1">,</span> <span class="token5">LEVELS</span> <span class="token2">as</span> levels <span class="token2">from</span> type_code where <span class="token5">PARENT_ID</span> <span class="token">=</span> <span class="token4">'30119a0e-2f57-473d-9f1d-2843561e9064'</span> and <span class="token5">ID</span> not <span class="token2">in</span> <span class="token1">(</span> select <span class="token5">PARENT_ID</span> <span class="token2">from</span> type_code where <span class="token5">PARENT_ID</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 结果满足查询的条件为空…… 后来发现,子查询中存在字段的某些值为null,所以导致了count=0. 所以,将SQL调整为如下: ``` <pre class="calibre13">``` select <span class="token5">ID</span> <span class="token2">as</span> id<span class="token1">,</span> <span class="token5">TYPE_CODE</span> <span class="token2">as</span> typeCode <span class="token1">,</span> <span class="token5">TYPE_NAME</span> <span class="token2">as</span> typeName <span class="token1">,</span> <span class="token5">PARENT_ID</span> <span class="token2">as</span> parentsId <span class="token1">,</span> <span class="token5">STYLE</span> <span class="token2">as</span> style <span class="token1">,</span> <span class="token5">LEVELS</span> <span class="token2">as</span> levels <span class="token2">from</span> type_code where <span class="token5">PARENT_ID</span> <span class="token">=</span> <span class="token4">'30119a0e-2f57-473d-9f1d-2843561e9064'</span> and <span class="token5">ID</span> not <span class="token2">in</span> <span class="token1">(</span> select <span class="token5">PARENT_ID</span> <span class="token2">from</span> type_code where <span class="token5">PARENT_ID</span> is not <span class="token2">null</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 这样就能正确的查出结果了! **总结:MySQL中如果要用not in在子查询中限制结果,那必须要将子查询的结果集限制为不含null,不然查询结果count = 0.**