I'm trying to set up a query to fetch results in a table where I need to determine a condition for one column, group for another, and display a third.
The database is composed of 6 tables, 5 of which are queried individually, containing: id
, entrada
, saida
, status
, materia
, exibir_entrada
, exibir_saida
compartilhada
.
Below is the basic structure image of the tables:
Sofar,Igetaquerygroupingbystory.Ididthequerylikethis:
$QueryBuscarAgruparMaterias = "SELECT count(*),materia FROM $NomeSala GROUP BY materia HAVING materia = 'Geografia'";
$ExeQrBuscarAgruparMaterias = mysql_query($QueryBuscarAgruparMaterias);
while ($MateriasAgrupadas = mysql_fetch_assoc($ExeQrBuscarAgruparMaterias)){
?>
<option value="<?php echo $MateriasAgrupadas['entrada'] ?>">
<?php echo $MateriasAgrupadas['entrada'] ?>
</option>
<?php
}
But the result does not show the information I need:
IeventriedtomakeaSELECTCOMPOUND:
select entrada, count(materia) from
(
select*from
(
select * from $NomeSala WHERE compartilhada = 1 AND materia = 'Geografia'
)
)as t GROUP BY materia;
Even so, I can not display the record of the entrada
column.
The data from this query will be used to insert a new record into another table, thus generating a schedule of classes, both shared and private.
The remaining values will be stored in a table with the schedules of the day as in the image has the table 03_01_2017
. This is where I need to enter the information.