都有哪些设计模式,最好能介绍下
设计模式是有13种么?谁能介绍下?或者有相关书籍的发我邮箱,yzsy0818@21cn.com,
更新时间:2024-01-26 17:01
最满意答案
当case when 条件中用了or,并且有where查询条件的情况下会出现问题,但如果这个 where 条件值不是 case when中的字段,是否会有不同结果,再来试验一下: select a.channel from ( select deviceid, case when channel = 'NA' or channel = 'EMPTY' then 'A' else 'B' end as channel from t_aa_pc_log where pt = '2012-04-10-00' )a where deviceid like '%a%' limit 10;
其他回答
首先从软件角度考虑 if加若干个else if可以组成一个与case类似的功能 但需要注意的是if-else if是有优先级的,也就是第一个if不成立的话,才判断第二个else if 那么问题就来了,如果这个if组合里有10个else if条件,那么逻辑就需要做一个在一个时钟周期内能判断10个条件的硬件电路来,这样是不明智也是不合理的,比较容易造成时序不满足 虽然说if有这样的缺点,但它的优点是每个else if都可以判断不同的条件,比较灵活 一般来说,如果判断的条件只是一个向量的不同值,那么case是最合适的 如果判断的条件是许多不同的向量或者变量,那么if还是比较合适的 当然也可以选择case和if的组合,这样灵活性和时序都比较好
相关问答
更多-
hive case when 不写else有关系吗[2023-04-07]
当case when 条件中用了or,并且有where查询条件的情况下会出现问题,但如果这个 where 条件值不是 case when中的字段,是否会有不同结果,再来试验一下: select a.channel from ( select deviceid, case when channel = 'NA' or channel = 'EMPTY' then 'A' else 'B' end as channel from t_aa_pc_log where pt = '2012-04-10-00' ... -
oracle 中的 nulls last 在 hadoop 的 hive 上 怎么写。。[2022-05-08]
order by nulls last 不是标准sql,oracle设计的 可以这么写,再指定一个虚拟列来辅助排序 order by case when col is null then 0 else 1 end , col desc -
你的查询看起来是正确的,我删除了一些额外的部分(但它不是必需的): SELECT b.Event_Name as Event_Name , COUNT(b.Event_Name) as event_occurrences , SUM(b.item_value) as user_spendings FROM (SELECT a.id as Player_ID , a.n as Event_Name , a.utc as timing COAL ...
-
Afaik我们不能在hive中的case语句中放置任何ddl或dml操作。 但是,如果真的需要解决,可以应用解决方法来解决上述问题。 insert into table team select 20, 'billy', 'bob' from team where team_id = 2; 说明: - 如果team_id = 2,它将在团队表中插入新记录,否则无需插入任何内容。 Afaik we can't put any ddl or dml operation in case statement in ...
-
我猜你的代码片段来自查询的SELECT子句? 根据Hive语言手册 :“Hive仅支持FROM子句中的子查询”。 您的CASE WHEN语句包含子查询。 似乎不支持,因此您的语法不正确(在Hive中)。 I'm guessing your snippet of code is from the SELECT clause of your query? According to the Hive Language Manual: "Hive supports subqueries only in the FR ...
-
NULL不能与等于(=)进行比较使用IS NULL而不是= NULL 。 你的逻辑等同于 case when your_time IS NULL OR my_time > your_time then my_time end as overall_time NULL can't be compared with an equal to (=) Use IS NULL instead of = NULL. Your logic is equivalent to case ...
-
Hive LIKE [0-9](Hive LIKE [0-9])[2023-05-30]
我想你想要一个正则表达式。 根据你的代码 : (Case When Substr(Upper(Trim(MBRCHR)),-3) rlike '^[8-9][0-9][A-E]$' Then Substr(Upper(Trim(MBRCHR)),-3) end) as DRVD, 我没有发现你的代码与描述相符。 Hive中的正则表达式匹配使用rlike或regexp (请参见此处 )。 I think you want a regular expression. Based on your ... -
Hive - SUM中的ELSE(Hive - ELSE in SUM)[2022-02-06]
假设entry_date是一个date ,你可能不想sum()它。 如果你想要不同范围内的运行时间总和,那么你想要一个像这样的select : SELECT entry_date, customer, cust_loc, SUM(run_time) AS TOTAL_RUN, SUM(CASE WHEN run_time BETWEEN 10000 AND 20000 THEN run_time ELSE 0 END) AS SLOT_1, ... -
案例 - 当Hive中的表名时(Case-When table name in Hive)[2023-09-14]
这个有可能。 像这样重写你的查询: SELECT col1, col2 FROM table1 WHERE '${PARAM}' = 'val1' --only one subquery will be executed union all SELECT col1, col2 FROM table2 WHERE '${PARAM}' = 'val2' This is possible. Rewrite your query like this: SELECT col1, col2 FROM table1 ... -
不需要collect_set select t1.c1 as f1 ,max(t2.c4) as f2 from sample_table1 t1 join sample_table2 t2 on t1.c2 = t2.c3 group by t1.c1 ; +-----+----+ | f1 | f2 | +-----+----+ | 001 ...