考虑表如何查询重复的元素?
CREATE TABLE `contact` (
`id` INTEGER,
`name` TEXT,
`category` INTEGER,
`freed` INTEGER DEFAULT 0,
PRIMARY KEY(id)
);
我想做出这样的查询或视图,将重复的行与freed = 1 AND caregory IS NOT NULL
,对于类别应设置为-1的行。应删除行(category is null and freed = 1)
。
第一张图片显示数据源。第二张照片显示所需结果。
3个新的行应增加(金,-1,1 | TIH,-1,1 | Traph,-1,1)
1原料是souldbe删除(Traph,空,1)
WHERE NOT(category is null and freed = 1)
ORDER BY category IS NULL ASC, category = -1 ASC, category ASC , name ASC
是否有可能使类似
CREATE VIEW v1 AS
SELECT s.name, s.category, s.freed
FROM contact s
CASE freed = 1 and category is not null
insert into v1(t.name,-1,1)
SELECT p.name
FROM contact p
WHERE s.name = p.name
不,但它可能就像我张贴在我的答案。视图代表一个选择查询,它不能更新或插入。 – sagi