首页 \ 问答 \ 都有哪些设计模式,最好能介绍下

都有哪些设计模式,最好能介绍下

设计模式是有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的组合,这样灵活性和时序都比较好

相关问答

更多
  • 当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' ...
  • 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 ...
  • 我想你想要一个正则表达式。 根据你的代码 : (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 ...
  • 假设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, ...
  • 这个有可能。 像这样重写你的查询: 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)