Ich habe drei Tabelleninhalt Informationen über BeiträgeMYSQL: select count mit Union drei Tabellen
und jede Tabelle hat post_id es ist foreign_key für Beitrag Tisch
first table = `likes`
second table = `Comment`
and last one = `Visitor`
jede Tabelle ein paar Informationen über die Nutzer wie Sitzung hat oder id und etc
ich brauche neue view-Tabelle enthalten Post-ID und die Anzahl der Besucher erstellen, mag, Kommentar
ich habe versucht, diese
SELECT *
from (
select id , count(id) as Comment
from Post left join Comment on id = Post_id
group by id
UNION
select id, count(id) as Visitor
from Post left join Visitor on id = Post_id
group by id
UNION
select id, count(id) as Likes
from Post left join Likes on id = Post_id
group by id
) CountsTable
GROUP BY CountsTable.id
aber es hat nicht funktioniert. ich weiß nicht, warum das Ergebnis nur die erste innere select ist
in meinem Beispiel das Ergebnis
ist| id | Comment|
|--------|------- |
| 1 | 55 |
| 2 | 25 |
| 3 | 12 |
ich etwas erwarten, wie die
| id | Comment | Likes | Visitor |
|--------------|-------|---------|
| 1 | 55 | 100 | 2000 |
arbeitete für mich danke, aber wenn ich versuchte, Blick von diesem zu machen ich habe „Ansicht SELECT eine Unterabfrage in der FROM-Klausel enthält“ – isams