0
I need to count table records acesso_registro
and show in a list.
Schema:
acesso_registro
+--------------+--------+------------+
|id_tipo_midia |id_midia| data_acesso|
+--------------+--------+------------+
|01 | 03 | 2019-06-03 |
|01 | 03 | 2019-06-03 |
|03 | 01 | 2019-06-05 |
|02 | 03 | 2019-06-06 |
|02 | 01 | 2019-06-06 |
|03 | 02 | 2019-07-08 |
+--------------+--------+------------+
tipo_midia
+--+-------+
|id| tipo |
+----------+
|01| Vídeo |
|02| Audio |
|03| Imagem|
|04| Outro |
+----------+
videos
+--+----------+
|id| titulo |
+-------------+
|01| video_01 |
|02| video_02 |
|03| video_03 |
|04| video_04 |
+-------------+
audios
+--+----------+
|id| titulo |
+-------------+
|01| audio_01 |
|02| audio_02 |
|03| audio_03 |
|04| audio_04 |
+-------------+
imagens
+--+-----------+
|id| titulo |
+--------------+
|01| imagem_01 |
|02| imagem_02 |
|03| imagem_03 |
|04| imagem_04 |
+--------------+
The query must return me:
*---------*---------*--------*
|tipoMidia| titulo | acessos|
*---------*---------*--------*
|vídeo |video_03 | 2 |
|Imagem |imagem_01| 1 |
|Imagem |imagem_02| 1 |
|Audio |audio_01 | 1 |
|Audio |audio_03 | 1 |
*---------*---------*--------*
Note: The table acesso_registro
increments a line whenever a media is accessed. The database I use is Postgres.
You mean you will decide which table to merge with according to the contents of the id_typo_midia field of the access table_record?
– anonimo
Yes! See that in the table
acesso_registro
, the first two lines show that there are two records for the media type "Video" tabletipo_midia
and that these two records are theid
03 of the tablevideos
, i.e., the "video_03".– Jfé
To simplify if you can complicate!
– anonimo