我有这个查询,我想检索结果,只按 分组Banksphere.servicio_id
,不做任何事情,sum(XXX)
因为每个Banksphere.servicio_id
都有自己的值,用hora_id
,peticion_id
和valor
...
所以结果一定是这样的......
[servicio_id 1]
(hora_id 1) (hora_id 2) (hora_id 3) ...
(peticion_id 1) (peticion_id 2) ...
(media 1) (media 1) ...
(valor 1) (valor 1) ...
...
[servicio_id 2]
(hora_id 1)
(peticion_id 1) (peticion_id 2) ...
(media 2)
(valor 2)
...
到目前为止我的查询 -
$sqlQuery = sqlsrv_query($conn, "
SELECT
Umbrales.minimo as media,
uok.minimo as media_ok,
Banksphere.id as valor_id,
Umbrales.id as umbral_id,
Banksphere.servicio_id,
Banksphere.peticion_id,
Banksphere.hora_id,
Banksphere.valor
FROM
Banksphere
LEFT JOIN
Umbrales
ON Banksphere.hora_id = Umbrales.hora_id
AND Banksphere.dia_id = Umbrales.dia_id
AND Banksphere.servicio_id = Umbrales.servicio_id
AND Banksphere.entidad_id = Umbrales.entidad_id
AND Banksphere.peticion_id = Umbrales.peticion_id
LEFT JOIN
Umbrales uok
ON Banksphere.hora_id = uok.hora_id
AND Banksphere.dia_id = uok.dia_id
AND Banksphere.servicio_id = uok.servicio_id
AND Banksphere.entidad_id = uok.entidad_id
AND uok.peticion_id = 0
WHERE
Banksphere.entidad_id = '$entidad_id'
AND
Banksphere.reconocido = 0
AND
Banksphere.fecha = '$fecha'
ORDER BY
Banksphere.servicio_id ASC,
Banksphere.hora_id DESC,
Banksphere.peticion_id ASC
");