我需要一个select查询:如何从多次出现的数据库中获取相同的plate_number
numbers
number_plate
示例数据:
plate_code plate_number
------------------------
A 45990
B 54667
c 45990
D 0908
E 54667
F 65534
G 3422
H 32009
I 0908
我希望输出看起来像这样:
A 45990
A 45990
B 54667
E 54667
I 0908
答案 0 :(得分:0)
请尝试使用此count(plate_number)
GROUP BY
和HAVING
语句。
$query = "SELECT plate_code,plate_number from table_name GROUP BY plate_number HAVING count(plate_number)>1";
答案 1 :(得分:0)
这很容易尝试这个
SELECT plate_code, plate_number
FROM table_name
WHERE plate_number IN (
SELECT plate_number
FROM table_name
GROUP BY plate_number
HAVING COUNT(id) > 1
ORDER BY plate_number ASC
) ORDER BY plate_number ASC