I have a simple query to get, but I'm stuck and I really can't figure out how to do this. More specifically: The table Allarmi has a lot of entries, which i show all grouped by Allarmi.IDComponente

我有一个简单的查询,但我卡住了,我真的无法弄清楚如何做到这一点。更具体地说:表Allarmi有很多条目,我显示所有条目由Allarmi.IDComponente分组

something like this

这样的事情

SELECT * 
FROM ALLARMI AS ALLARMI
WHERE ID_CELLA = 1
GROUP BY ID_Componente

I only need to add to this table a COUNT column, something like

我只需要在这个表中添加一个COUNT列,就像这样

(SELECT COUNT( * ) 
FROM allarmi
WHERE isAttivo = 1
GROUP BY id_componente)

but I would like to show COUNT even when its 0 or NULL

但我想显示COUNT,即使它的0或NULL

How can I do it? Thanks in advance

我该怎么做?提前致谢

1 个解决方案

#1


1

Assuming table Componenti defines the components, and you want to get a count of records from allarmi for each component, what you actually want to do is select the component from Componenti and add a LEFT OUTER JOIN on allarmi

假设表Componenti定义了组件,并且您希望从allarmi获取每个组件的记录计数,您实际想要做的是从Componenti中选择组件并在allarmi上添加LEFT OUTER JOIN

SELECT COMPONENTI.ID_Componente, COUNT(ALLARMI.ID_Componente)
FROM COMPONENTI
LEFT OUTER JOIN ALLARMI ON
   -- insert your join here!
   -- maybe COMPONENTI.ID_Componente= ALLARMI.ID_Componente?
   -- add any query for this table here as well.
   AND ALLARMI.ID_Cella = 1
GROUP BY COMPONENTI.ID_Componente

更多相关文章

  1. 在时间戳和相应的值中选择每天的最后一个条目。
  2. react系列(一)JSX语法、组件概念、生命周期介绍
  3. 如何从Vue.js中的变量名加载组件?
  4. Angular 2快速入门 - 我的应用程序组件未加载
  5. React组件的属性PropTypes
  6. $ postLink的角度组件/指令运行得太早
  7. 如何在没有pdf组件的移动浏览器中显示Base64编码的pdf
  8. 日志与python日志组件logging
  9. 具有1位条目的numpy布尔数组

随机推荐

  1. golang gf怎么使用
  2. golang map有什么用
  3. golang和erlang区别
  4. golang gin框架错误处理
  5. golang中创建错误的方法
  6. golang chan是否关闭
  7. golang web开发乱码的原因与解决方法
  8. golang与java语法上的区别
  9. golang-cache是全局吗
  10. golang中使用rand产生随机不重复数字