問題描述
Đếm từ hai bảng và sắp xếp nó theo số lượng SQL tồn tại (Count from two tables and sort it out by the number of exist SQL)
I’ve trying to list out a table with numbers that exist more than three time. As you can see, I am new to SQL. I am a bit unsure about the syntaxes and possibilities with SQL.
I have tried this:
SELECT tabel1.nr, count(tabel2.opp)
FROM tabel1
JOIN tabel2 on tabel2.opp = tabel1.opp
WHERE tabel2.opp > 3
ORDER BY tabel2.opp
This is the idea I’ve trying to figure out:
SELECT COUNT(tabel1.key = tabel2.key) as numbers
FROM table1
ORDER BY numbers > 3
參考解法
方法 1:
try this
SELECT tabel1.nr, count(tabel2.opp)
FROM tabel1
JOIN tabel2 on tabel2.opp = tabel1.opp
GROUP BY tabel1.nr
HAVING count(tabel2.opp) > 3
ORDER BY tabel2.opp