select

Hive性能优化——配置角度

爱⌒轻易说出口 提交于 2020-04-06 02:20:48
我们可以从Hive的配置解读去优化。Hive系统内部已针对不同的查询预设定了优化方法,用户可以通过调整配置进行控制, 以下举例介绍部分优化的策略以及优化控制选项。 列裁剪 Hive在读取数据时,可以只读取查询所需要的列,而忽略其他的列。列如,若有以下查询:SELECT a,b FROM q WHERE e<10;在实施此查询时,q表有5列(a,b,c,d,e),Hive只读取查询逻辑中真实需要的3列a、b、e,而忽略c,d;这样做节省了读取开销,中间表存储开销和数据整合开销。裁剪所对应的参数项为: hive.optimize.cp=true (默认值为真) 分区裁剪 可以在查询过程中减少不必要的分区。列如,若有以下查询: SELECT FROM(SELECT a1,COUNT(1) FROM T GROUP BY a1) subq WHERE subq.prtn = 100 ;#(多余分区) SELECT FROM T1 JOIN (SELECT * FROM T2) subq ON (T1.a1=subq.a2) WHERE subq.prtn = 100 ;查询语句若将"subq.prtn=100"条件放入子查询中更为高效,可以减少读入的分区数目。Hive自动执行这种裁剪优化。分区参数为: hive.optimize.pruner=true (默认值为真)。 JOIN操作

Div被Select挡住的解决办法

无人久伴 提交于 2020-04-06 00:23:55
Div被Select挡住,是一个比较常见的问题。 有的朋友通过把div的内容放入iframe或object里来解决。 可惜这样会破坏页面的结构,互动性不大好。 这里采用的方法是: 虽说div直接盖不住select 但是div可以盖iframe,而iframe可以盖select, 所以,把一个iframe来当作div的底, 这个div就可以盖住select了. < html > < head > < meta http - equiv = " Content-Type " content = " text/html; charset=gb2312 " > < title > 支持民族工业,尽量少买X货 </ title > </ head > < body > < div style = " z-index:10;position:absolute;width:100;height:18;overflow:hidden; " onmouseover = " this.style.height=100; " onmouseout = " this.style.height=18; " > < iframe style = " position:absolute;z-index:-1;width:100%;height:100%;top:0;left:0;scrolling:no; "

平边的Select制作方法

一笑奈何 提交于 2020-04-05 23:40:53
1: < span id ="SelectBorder" style ="border:1px solid #5884c8; position:absolute;" > < SELECT id ="objSelect" style ="position:absolute; margin:-1;" > < OPTION > 一个平边的Select </ OPTION > < OPTION > 1234567890 </ OPTION > < OPTION > DSclub </ OPTION > < OPTION > www.cnblogs.com/dsclub </ OPTION > < OPTION > 99670303 </ OPTION > </ SELECT > </ span > < SCRIPT LANGUAGE =javascript> <!-- objSelect.style.clip = 'rect(2px, ' + (objSelect.offsetWidth - 2) + 'px, ' + (objSelect.offsetHeight - 2) + 'px, 2px)'; SelectBorder.style.width = objSelect.offsetWidth; SelectBorder.style.height = objSelect

防SQL注入

谁都会走 提交于 2020-04-05 22:25:25
View Code 1 /// <summary> 2 /// 防注入 3 /// </summary> 4 /// <param name="content">提交的内容</param> 5 /// <returns></returns> 6 public static string PreventScriptIncludeSQL(this string content) 7 { 8 int i = 0; 9 string sqlchar = "insertinto|deletefrom|altertable|update|createtable|createview|dropview|createindex|dropindex|createprocedure|dropprocedure|createtrigger|droptrigger|createschema|dropschema|createdomain|alterdomain|dropdomain|select@|declare@|print@|char(";10 string[] sqlchars = sqlchar.Split('|');11 for (i = 0; i < sqlchars.Length; i++)12 {13 content = content.Replace(" ", "").ToLower()

sql示例

放肆的年华 提交于 2020-04-05 21:06:46
-- table_1中有id,age; table_2中有id,sex。想取出id,age,sex 三列信息,-- 将table_1,table_2 根据主键id连接起来 select a.id,a.age,b.sex from (select id,age from table_1) a join (select id, sex from table_2) b on a.id =b.id ================想知道有多少去重的用户数 select count(*) from ( select distinct id from table_1) tb ================ 将数值型的变量转化为分类型的变量?—— case when 条件函数 -- 收入区间分组 select id, ( case when CAST(salary as float)< 50000 Then '0-5万' when CAST(salary as float)>= 50000 and CAST(salary as float)< 100000 then '5-10万' when CAST(salary as float) >= 100000 and CAST(salary as float)< 200000 then '10-20万' when CAST(salary as

Oracle创建设置查询权限用户

允我心安 提交于 2020-04-05 20:44:18
--普通用户test,需要创建查询用户(cxtest),授权test的部分表或试图查询权限 -- 使用 SYSTEM创建用户 create user cxtest identified by cxtest default tablespace USERS temporary tablespace TEMP profile DEFAULT; grant create session to cxtest; grant create synonym to cxtest; ---test用户赋权VJK_WBFK_CPXX、VJK_WBFK_GZB、VJK_WBFK_QMCCB给cxtest grant select on VJK_WBFK_CPXX to cxtest; grant select on VJK_WBFK_GZB to cxtest; grant select on VJK_WBFK_QMCCB to cxtest; --cxtest用户建同义词 create synonym VJK_WBFK_CPXX for test.VJK_WBFK_CPXX; create synonym VJK_WBFK_GZB for test.VJK_WBFK_GZB; create synonym VJK_WBFK_QMCCB for test.VJK_WBFK_QMCCB; --

Mysql 查询天、周,月,季度、年的数据

Deadly 提交于 2020-04-05 20:31:56
今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1 近7天 SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名) 近30天 SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名) 本月 SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) 上一月 SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =1 查询本季度数据 select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now()); 查询上季度数据 select * from `ht

sql 强化练习 (七)

拟墨画扇 提交于 2020-04-05 20:21:22
继续 sql 练习, 不能停下来的哦, 通过这一系列的搬砖操作, 相信在日常业务的sql 应该是能达到相对清楚地写出来的, 尤其是我做数据分析这块, 感觉真的每天都要写才行, 之前都是用 Python 来轻松搞定, 但仔细一想, sql 才是最通用的哦, sql 熟练了, 我感觉, 数据分析的基础工作就已经完成一半了, 剩下的指标计算, 这些不就是简单的 加减乘除而已, 分分钟脚本批量处理它. 表关系 需求 查询 和 0001 号同学, 所学课程 完全相同的 其他同学的学号. 分析 先查出 0001 这个兄弟, 的所有课程 id; 然后查出 not in 这些 课程 id 的这些 学号; 还要完全相同, 则, group by s_id 后, 选课的数量还必须一致哦. 从 3 中 排除掉 2 中的 id 剩下的就是满足条件的啦 -- 1. 先看看 0001 这个兄弟选了哪些课程 select c_id from score where s_id = '0001'; +------+ | c_id | +------+ | 0001 | | 0002 | | 0003 | +------+ 3 rows in set (0.01 sec) 都给选上了. 即下一步, 要找的学生, 必须都同时选了 1,2,3号课程, 注意不能多哦 , 要完全相同. -- 2. 反向来看, 没有跟

项目讲解4

流过昼夜 提交于 2020-04-05 19:57:34
分组取topN的方法: 数据的预处理为使用mapreduce 每日新访客: 回头/单次访客统计: 漏斗模型: 使用python产生数据 1.统计每个步骤的总访问人数 create table tmp_page_views like ods_weblog_origin;创建一个像 ods_weblog_origin这个表格式的表 desc tmp_page_views; 把python生成的mylog.log数据导入 统计每个step的数量:( 为什么要加这个?step1 as step ) select‘step1’ as step ,count(distinct remote_order) as number from tmp_page_views where request like '%/iterm%'; union就是把行并在一起,把表纵向加起来 把拼接的表放到route_number中 create table dw_oute_numbs as select 'step1' as step,count(distinct remote_addr) as numbs from ods_click_pageviews where request like '/item%' union select 'step2' as step,count(distinct remote

慎用create table as select,不会copy约束,主键什么东东都不会复制

自作多情 提交于 2020-04-05 18:34:04
1、再做一些数据迁移时候,很多人会使用create table as select * from table where id=-1的方式来年建立一摸一样的表,但是这样做有个很大的弊端,不能将原表中的default value也一同迁移过来。 2、 Using the CREATE TABLE ... AS SELECT ... command: This command will copy acrooss to the new table all the data,but the constraints triggers ,and so on will not be transferred to the new table. 那些都是not null约束,其他的约束和trigger是带不过来了,严格说来not null也是约束的一种,只不过教材上把它排除在外了吧。 慎用create table as select,一定要注意默认值的问题 博客分类: Oracle oracle create talbe as select 数据库迁移 再做一些数据迁移时候,很多人会使用create table as select * from table where id=-1的方式来年建立一摸一样的表,但是这样做有个很大的弊端,不能将原表中的default value也一同迁移过来