从表中计算某一列相同字段的个数,并且按照降序排列
select pcmtxt, count(*) as counts from pcm2txt_db_1 group by pcmtxt order by counts desc;
count(*)—-计数函数
as counts —-输出到counts列
group by 把相同字段分为一组
order by counts desc —- 按照counts的降序排列
删除表格
drop table tablename;
重命名table
ALTER TABLE table_name RENAME TO new_table_name;
替换表中某个字段中的字符串
update table[表名] set Fields[字段名]=replace(Fields[字段名],'被替换原内容','要替换成的内容')
postgresql用表A中的数据更新表B中的数据(set后的item不要跟表名)
update A set item = B.item from B where A.item = B.item;通过coalesce可以筛选出不为pcmtxt不为空的项
select * into baidud50 from baidu50k where pcmtxt=coalesce(pcmtxt, null);
往字段里增加内容, postgresql用“||”追加字符串
update cmww set comment=(comment || '(内测数据)') where comment is null;
-导出数据到csv
copy (select * from cmww) to '/home/nitb/cmww.csv' with csv header;