我开始阅读更深入的MySql并尝试在description上解决此任务。根据描述需要从表中删除重复项,但我的查询不起作用。在sqllite工作正常。是什么原因?
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
public static void sendSimpleMessage(String recipient) {
Client clientMail = ClientBuilder.newBuilder().build();
clientMail.register(HttpAuthenticationFeature.basic("api", MAILGUN_API_KEY));
WebTarget targetMail = clientMail.target("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
Form formData = new Form();
formData.param("from", "Mailgun Sandbox <"+DOMAIN_MAIL_ADDRESS+">");
formData.param("to", recipient);
formData.param("subject", "Simple Mailgun Example");
formData.param("text", "Plaintext content");
Response response = targetMail.request().post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
System.out.println("Mail sent : " + response);
}
错误
DELETE
FROM
Person
WHERE
Email IN(
SELECT
Email
FROM
Person
GROUP BY
Email
HAVING
COUNT(Email) > 1
);
答案 0 :(得分:1)
您可以使用自联接来删除重复项
delete a
from Person a
left join Person b on a.Email = b.Email
and a.id > b.id
where b.Email is not null
+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+