0
I am creating an SQL query that will be used in a system/report and came across the following problem. It has two results, one that displays the total time between the days searched and the other that will be displayed day by day. The difficulty in the case is in the second screen I have to create.
The Case Consultation is like this
SELECT ocorrencias.[GITEC]
,SUM(DATEDIFF(SECOND, ocorrencias.[INICIO], ocorrencias.[FECHAMENTO
OCORRÊNCIA])) as Total_Indispo
FROM [REPORT].[dbo].[report_sirea] ocorrencias INNER JOIN [REPORT].
[dbo].[planta_circuitos] circuitos
ON ocorrencias.[CIRCUITO] = circuitos.[DESIGNACAO] WHERE
ocorrencias.[INICIO] BETWEEN '2019-07-01' AND '2019-07-03 23:59:59'
AND ocorrencias.[FECHAMENTO OCORRÊNCIA] IS NOT NULL
AND ocorrencias.[GITEC] = 'GITEC/BH'
AND circuitos.[TIPO_PONTO] NOT IN ('LOTERICOS',
'BACKBONE','INTERLIGAÇÃO - BACKBONE')
GROUP BY ocorrencias.[GITEC]
ORDER BY [ocorrencias].[GITEC]
In the case would also have to present the results dynamically separately, In case would need to show on 01, after the 02 and last the day 03.
It is possible to do this directly in SQL only using a Select or would need something else (Function, Procedure) or would need to do it directly in PHP language?
In this case, I am using SQL Database Server.
you can make a process that loads all the results in a temporary table and returns everything at once to the end with all the results you need. Another solution would be to assemble multiple selects, run all and pay the various results using
mysqli_multi_query
. If you need help with any of these options I can help with an answer– Ricardo Pontual
Can you provide table structure, example data for tables, and an expected result for these example data? Without it it’s hard to visualize what you want
– Sorack