Postgresql 常用SQL语句
1 查询表中重复数据
SELECT * FROM "tbScenics"
WHERE "Scenic_Id"
NOT IN (
SELECT max("Scenic_Id")
FROM "tbScenics"
GROUP BY "Scenic_Name", "Scenic_Des", "Scenic_Price", "Scenic_Ticket"
);
2 删除表中重复数据
DELETE * FROM "tbScenics"
WHERE "Scenic_Id"
NOT IN (
SELECT max("Scenic_Id")
FROM "tbScenics"
GROUP BY "Scenic_Name", "Scenic_Des", "Scenic_Price", "Scenic_Ticket"
);
3 sql 更新一列为行号
update u_menu
set issort=t1.rowId
from
(
--select * from
--(
select cmenu_id,ROW_NUMBER() over(Order by cmenu_id) as rowId
from u_menu
) as t1
where t1.cmenu_id=u_menu.cmenu_id
--) as t
4 PostgreSQL修改字段ID自增长
CREATE SEQUENCE id_seq START WITH 5;
ALTER TABLE guarantee_contract_open_status ALTER COLUMN id SET DEFAULT nextval('id_seq'::regclass);
赞 (0)