这是来自 LEETCODE 的一个问题。我不知道为什么我的输出是错误的。首先,我在括号中写入 SELECT 以找出重复的电子邮件地址。然后我使用 DELETE 过滤掉重复的电子邮件地址,这样有人知道我的代码有什么问题吗? questionmycode output
答案 0 :(得分:1)
很简单。试试这个
-- 解决方案 1
router.get("/", (req, res) => {
console.log(Questions);
// Questions.then(() => {
// res.send(Questions);
// })
res.status(200).send({
res: "Success",
}
const newData = Questions;
newData.forEach(function(obj, i) {
obj['answer'] && delete obj['answer'];
});
res.send(newData);
);
});
-- 解决方案 2
with cte as
(
select id, email, Rank() OVER (partition by email order by id) ranks
from person where email in(
select email from person
group by email having count(email) >1
)
)
DELETE FROM person where id in
(
SELECT id FROM CTE where ranks!=1
)