Đế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)


問題描述

Đế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

(by kvambaamrs.)

參考文件

  1. Count from two tables and sort it out by the number of exist SQL (CC BY‑SA 3.0/4.0)

#sql-order-by #MySQL #mysql-workbench #jointable #count






相關問題

如果提到,按特定值自定義 SQL 記錄集順序 (Customize SQL recordset order by specific value (s) if mentioned)

SQL Server 中的 OrderBy 將正值放在負值之前 (OrderBy in SQL Server to put positive values before negative values)

Đế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)

按組中的最大值排序 (Order by the max value in the group)

.net中的SQLite中不區分大小寫的順序 (case insensitive order by in SQLite in .net)

MySQL:對 GROUP_CONCAT 值進行排序 (MySQL: Sort GROUP_CONCAT values)

為 MySQL 選擇查詢自定義 order by (Customize order by for MySQL select query)

如何從 MySQL 表中檢索 10 個最新的 DISTINCT IP? (How to retrieve 10 latest DISTINCT IP's from a MySQL table?)

按存儲在文本列中的日期排序表 (Order table by date stored in text column)

如何在 JavaScript 中對對象集合進行自然排序? (How to natural-sort a collection of objects in JavaScript?)

在 Postgres 中通過 json 數組(存儲為 jsonb)中的鍵對錶進行排序 (Order a table by a key in an array of json (stored as jsonb) in Postgres)

添加 row_number() 時 Oracle 值發生變化 (Oracle values change when row_number() added)







留言討論