SQL跳过如果值为空。

huangapple go评论76阅读模式
英文:

SQL skip is value is null

问题

I have this SQL:

SELECT
  JSON_VALUE(DATA, '$.name') AS name,
  JSON_VALUE(DATA, '$.total') AS total,
FROM `somewhere`

It produces data such as:

Leon   null    
Ashlee 38
Peter  null

I want to only return records where total is not null. What do I need to adjust in my query? I know it's probably a WHERE, but I never work with SQL so not sure what.

英文:

I have this SQL:

SELECT
  JSON_VALUE(DATA, '$.name') AS name,
  JSON_VALUE(DATA, '$.total') AS total,
FROM `somewhere`

It produces data such as:

Leon   null	
Ashlee 38
Peter  null

I want to only return records where total is not null. What do I need to adjust in my query? I know it's probably a WHERE, but I never work with SQL so not sure what.

答案1

得分: 1

你应该将它添加到 where 子句中
并使用 IS NOT NULL 过滤器

以下是查询:

SELECT
  JSON_VALUE(DATA, '$.name') AS 名称,
  JSON_VALUE(DATA, '$.total') AS 总数,
FROM `某处`
WHERE
     JSON_VALUE(DATA, '$.name') 不是空的
英文:

You should add it in where clause
and IS NOT NULL filter

Here is the query:

SELECT
  JSON_VALUE(DATA, '$.name') AS name,
  JSON_VALUE(DATA, '$.total') AS total,
FROM `somewhere`
WHERE
     JSON_VALUE(DATA, '$.name') IS NOT NULL

huangapple
  • 本文由 发表于 2023年3月7日 07:44:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定