使用下面显示的代码:

SELECT c.idBase, t.Estado FROM argentina.Tickets_2018 t
LEFT JOIN argentina.ContenidoBases c
ON t.ANI = c.ANI
WHERE t.idCampania = 8 AND t.Fecha BETWEEN "2018-04-04" AND "2018-04-15"


检索到的列和数据是这样的:

Base  |   Estado
----------------
139   |  ANSWER
139   |  ANSWER
139   |  NOANSWER
139   |  NOANSWER
139   |  ANSWER


我想要的是查看这样的信息(总计):

Base  |   Estado   |   Total
----------------
139   |  ANSWER    |     3
139   |  NOANSWER  |     2


我在代码中做错了什么? (我有很多“基础”(例如139、45、2等))

最佳答案

SELECT c.idBase, t.Estado, count(*) as total FROM argentina.Tickets_2018 t
LEFT JOIN argentina.ContenidoBases c
ON t.ANI = c.ANI
WHERE t.idCampania = 8 AND t.Fecha BETWEEN "2018-04-04" AND "2018-04-15"
Group by c.idBase, t.Estado


group by将允许您进行计数,这将为您提供总计:)

10-08 02:05