随笔分类 -  SQL

有关PostgreSQL和mysql数据库的操作
摘要:一、CONCAT()函数CONCAT()函数用于将多个字符串连接成一个字符串。使用数据表Info作为示例,其中SELECT id,name FROM info LIMIT 1;的返回结果为+ + +| id | name |+ + +| 1 | BioCyc |+ + +1、语法及使用特点:CONC 阅读全文
posted @ 2017-09-01 13:43 esther-qing 阅读(219) 评论(0) 推荐(1)
摘要:drop、truncate和delete的区别 (1)DELETE语句执行删除的过程是每次从表中删除一行,并且同时将该行的删除操作作为事务记录在日志中保存以便进行进行回滚操作。 TRUNCATE TABLE 则一次性地从表中删除所有的数据并不把单独的删除操作记录记入日志保存,删除行是不能恢复的。并且 阅读全文
posted @ 2017-07-19 19:49 esther-qing 阅读(177) 评论(0) 推荐(0)
摘要:1、MySQL相对来说比较年轻,首度出现在1994年。它声称自己是最流行的开源数据库。MySQL就是LAMP(用于Web开发的软件包,包括 Linux、Apache及Perl/PHP/Python)中的M。构建在LAMP栈之上的大多数应用都会使用MySQL,包括那些知名的应用,如 WordPress 阅读全文
posted @ 2017-07-19 19:00 esther-qing 阅读(6273) 评论(0) 推荐(0)
摘要:一、coalesce COALESCE (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值。如果所有的表达式都是空值,最终将返回一个空值。使用COALESCE在于大部分包含空值的表达式最终将返回空值。 阅读全文
posted @ 2017-04-01 16:20 esther-qing 阅读(366) 评论(0) 推荐(0)
摘要:over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用。其参数:over(partition by columnname1 order by columnname2)含义:按columname1指定的字段进行分组排序,或者说按字段columnn 阅读全文
posted @ 2017-03-30 14:56 esther-qing 阅读(2556) 评论(0) 推荐(0)
摘要:而不像预计的前两条。 阅读全文
posted @ 2017-03-30 12:00 esther-qing 阅读(177) 评论(0) 推荐(0)
摘要:update t1 set age=t2.age,name=t2.name from t2 where t1.id=t2.id; update t_company_infoset score = b.score, tech_score = b.tech_score, project_score = 阅读全文
posted @ 2017-01-11 14:31 esther-qing 阅读(359) 评论(0) 推荐(0)
摘要:【mysql】Date和String的互相转换(DATE_FORMAT & STR_TO_DATE) 1.Date ——> String 使用的函数:DATE_FORMAT(date,format) date:需要转换的日期 format:格式化的样式 format样式整理: 年: %Y 显示四位 阅读全文
posted @ 2016-12-07 13:51 esther-qing 阅读(10313) 评论(0) 推荐(0)
摘要:1.CREATE TABLE public.t_file ( id INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('t_file_id_seq'::regclass), file_name CHARACTER VARYING(100), content B 阅读全文
posted @ 2016-12-02 09:36 esther-qing 阅读(6737) 评论(0) 推荐(0)
摘要:select setval('t_custom_model_id_seq',1,false); 阅读全文
posted @ 2016-11-16 11:08 esther-qing 阅读(5454) 评论(0) 推荐(0)
摘要:select * from t where flag=1 order by abs(index) desc 阅读全文
posted @ 2016-11-11 14:50 esther-qing 阅读(4637) 评论(0) 推荐(0)
摘要:select country, sum( case when sex = '1' then population else 0 end), --男性人口 sum( case when sex = '2' then population else 0 end) --女性人口 from table_a 阅读全文
posted @ 2016-09-26 13:55 esther-qing 阅读(17360) 评论(0) 推荐(0)
摘要:1.int装string select CAST (1234 AS text) --5 附: PostgreSQL 类型转换函数 to_char (timestamp, text ) to_char ( double precision , text ) 阅读全文
posted @ 2016-09-26 11:46 esther-qing 阅读(18957) 评论(0) 推荐(1)
摘要:select round(1::numeric/4::numeric,3);结果为0.25select round( cast ( 1 as numeric )/ cast( 4 as numeric),2); 阅读全文
posted @ 2016-09-26 11:01 esther-qing 阅读(7377) 评论(0) 推荐(0)
摘要:1.获取当前日期的年份 阅读全文
posted @ 2016-09-26 10:59 esther-qing 阅读(34703) 评论(0) 推荐(0)