我有 2 个工作 MYSQL 语句,我想合并到 1 个查询中:
来自具有唯一和最大选择的mysql select语句?我有:
SELECT field_a, max(dup_number) as dup FROM table1 GROUP BY field_a
我的第二个查询是:
where contacts=0 ORDER BY date LIMIT 3
因此一组记录的示意图如下所示:
ID FIELD A DUP_NUMBER CONTACTS
1 text1 0 1 --
2 text2 0 3 --
3 text2 1 3 --
4 text2 2 3 --
5 text3 0 2 --
我想出了:
SELECT *
FROM `table1 `
where max(`DUP_NUMBER `) as dup and `CONTACTS`=1
GROUP BY `FIELD_A`
ORDER BY date
LIMIT 3
当我在 PHPMyAdmin 中测试时,我得到
#1064 - You have an error in your SQL syntax.
谁能告诉我如何正确地重写它?