从两个表中计数并按存在的SQL数排序

时间:2013-03-25 21:50:49

标签: mysql count sql-order-by mysql-workbench jointable

我试图列出一个表格,其中包含三次以上的数字。如您所见,我是SQL新手。我对SQL的语法和可能性有点不确定。

我试过这个:

SELECT tabel1.nr, count(tabel2.opp)
FROM tabel1
JOIN tabel2 on tabel2.opp = tabel1.opp
WHERE tabel2.opp > 3
ORDER BY tabel2.opp

这是我想弄清楚的想法:

SELECT COUNT(tabel1.key = tabel2.key) as numbers
FROM table1
ORDER BY numbers > 3

1 个答案:

答案 0 :(得分:3)

试试这个

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