首先,我使用Doctrine2和Symfony2使用MySQL数据库。 我有以下实体,它与其他人有关系,如你所见。Doctrine2复杂统计查询
Pge\IncidenciasBundle\Entity\Incidencia:
type: entity
table: incidencia
repositoryClass: Pge\IncidenciasBundle\Entity\IncidenciaRepository
id:
id:
type: integer
generator:
strategy: IDENTITY
fields:
fechaInicio:
type: date
nullable: false
column: fecha_inicio
fechaFinal:
type: date
nullable: true
column: fecha_final
horaInicio:
type: time
nullable: true
column: hora_inicio
horaInicioIndisp:
type: time
nullable: true
column: hora_inicio_indisp
horaFinal:
type: time
nullable: true
column: hora_final
horaFinalIndisp:
type: time
nullable: true
column: hora_final_indisp
causa:
type: text
nullable: true
resumen:
type: string
length: 250
fixed: false
nullable: true
descripcion:
type: text
nullable: true
solucion:
type: text
nullable: true
remedy:
type: string
length: 250
fixed: false
nullable: true
accionesRealizadas:
type: text
nullable: true
column: acciones_realizadas
manyToOne:
prioridad:
targetEntity: Prioridad
estado:
targetEntity: Estado
indisponibilidad:
targetEntity: Indisponibilidad
cliente:
targetEntity: Cliente
inversedBy: incidencia
servicio:
targetEntity: Servicio
lifecycleCallbacks: { }
我试图做一个查询,我检索数据给出的日期,这个输出(图像是在HTML中的手工表)
所以,对于每一个Cliente
我需要每行中打印的表格,其Servicio
,并为每个Prioridad
的发现Incidencia
这样一个计数器,如果有3 Incidencia
与Prioridad = P0
,1 Prioridad = P1
和2 Prioridad = P3
为Servicio = KOSMOS
和Cliente = Someone
,该表将输出这个
Someone
SERVICIO P0 P1 P2 P3
KOSMOS 3 1 0 2
它只是作为简单的,但我的问题是,我无法找到产生这种查询的方式......我试图创建多个磁盘阵列与一些foreachs和一些querys的东西,创建一个Cliente
分离的数组,并为每个日期,服务等数组,但我找不到方法来计数Prioridad
,这显然不是一个好的做法,因为有约8个foreach,foreach内查询等...所以不好,但我真的迷失了...
我认为必须有一个简单的方法来做到这一点,但不是我的知识...