微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果按值分组大于 1,Mysql 查询决定类型,则视为类型 2,否则为 1

如何解决如果按值分组大于 1,Mysql 查询决定类型,则视为类型 2,否则为 1

我想在按通道值分组时在mySQL查询中写一个case条件,如果计数大于1,它被认为是type_id 3,如果通道值没有重复,那么type_id应该是2 否则 0

select b.ChannelValue
case
when count(*),ChannelValue from tableb group by ChannelValue having count(*)=1 then 2
when count(*),ChannelValue from tableb group by ChannelValue having count(*)>1 then 3
else 0 END  AS type_id
from tablea a inner join tableb b
on a.ChannelValue = b.ChannelValue;

帮帮我!

解决方法

您可以使用以下内容:

let item = doc.data()
Promise.all([
  PostRawData(doc.data().RawData),checkBoundaries(doc.data().RawData),]).then(function (result) {
  item.decryptedData = result[0].data;
  item.colorIcon = result[1]
  items.push(item)
})

如果你有这个测试数据:

select ChannelValue,case
when (
  select count(*) from tableb 
  group by tableb.ChannelValue 
  having tableb.ChannelValue = tablea.ChannelValue) = 1 then 2
 when(
  select count(*) from tableb 
  group by tableb.ChannelValue 
  having tableb.ChannelValue = tablea.ChannelValue) > 1 then 3
 else 0
END as type_id
from tablea;

查询将返回:

ChannelValue type_id
100 3
200 0
300 2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。