coalesce

oracle null 空值排序- NVL,COALESCE , GREATEST ,LEAST

和自甴很熟 提交于 2020-01-19 11:35:44
1. COALESCE 返回该表达式列表的第一个非空value。 格式: COALESCE( value1, value2, value3, ... ) 含义: 返回value列表第一个非空的值。 value列表必须是相同类型,也可以是一个表的同一行、不同列的值进行比较。 EXAMPLE: select coalesce (1, null, 2 ) from dual ; -- 返回1 select coalesce ( null, 2, 1 ) from dual ; -- 返回2 select coalesce (t.empno, t.mgr ) from scott.emp t ; -- 效果类似 NVL( t.empno, t.mgr ) 2. GREATEST 返回值列表中最大值 格式: GREATEST( value1, value2, value3, ... ) 含义: 返回value列表最大的值。 value列表必须是相同类型,也可以是一个表的同一行、不同列的值进行比较。 当value值列表中有一个为NULL,则返回NULL值。 EXAMPLE: select greatest (1, 3, 2 ) from dual ; -- 返回3 select greatest ( 'A', 'B', 'C' ) from dual ; -- 返回C select

How to concatenate columns in a Postgres SELECT?

瘦欲@ 提交于 2020-01-18 19:34:56
问题 I have two string columns a and b in a table foo . select a, b from foo returns values a and b . However, concatenation of a and b does not work. I tried : select a || b from foo and select a||', '||b from foo Update from comments: both columns are type character(2) . 回答1: With string type columns like character(2) (as you mentioned later), the displayed concatenation just works because, quoting the manual: [...] the string concatenation operator ( || ) accepts non-string input, so long as at

Spark优化 – 基础篇

邮差的信 提交于 2020-01-14 19:13:16
  大数据调优总体方向:CPU,内存以及IO(Disk,Network)三个方面来进行。   对于多次使用的数据(RDD/DataFrame),通过cache()或者persis()来进行缓存,避免每一次都从数据源获取(减少磁盘IO); 系统资源优化   如下参数可以进行调优(可以参见附录中介绍的spark和yarn的交互内容): num-executors :executor数量(Spark Job的进程数量);结合executor-core进行考虑,两者相乘的量[40,100],尽量不要超过YARN的总core的指定比例,有的说25%,有的说50% executor-memory :executor内存上线,建议8G左右,申请的内存总量(num-executors*executor-memory)不要超过YARN的80%; executor-cores :executor的核数(线程数),即并行执行task的数据量,建议值4个,总量不要超过YARN总核数的50%; driver-memory :默认1G,足以。 spark.default.parallelizm :spark的并行度,默认数是待处理数据的hdfs的datablock数量;但是如果数据量很大的话明显不合适,task数量>>core的数量会拉低效率;spark官方建议要么是和分配的从cores数量保持一致

Spark Structtype for coalesce

房东的猫 提交于 2020-01-14 14:40:51
问题 I use Spark 2.0.1 Scala 2.11 How to provide a default value using coalesce for a column that's a StructType ? Say ... val ss = new StructType().add("x", IntegerType).add("y", IntegerType) val s = new StructType() .add("a", IntegerType) .add("b", ss) val d = Seq( Row(1, Row(1,2)), Row(2, Row(2,3)), Row(2, null) ) val rd = sc.parallelize(d) val df = spark.createDataFrame(rd, s) Now, df.select($"b").show results in +-----+ | b | +-----+ |[1,2]| |[2,3]| | null| +-----+ My question is how can I

MySQL, multiple rows to separate fields

放肆的年华 提交于 2020-01-11 08:52:48
问题 I have a MySQL table with fields and data such as follows; PartNumber Priority SupName a1 0 One a2 0 One a2 1 Two a3 0 One a4 1 Two a5 2 Three I am trying to create a view where the parts that have multiple rows are combined into a single row, and into separate fields such as Ideally This; PartNumber Sup1 Sup2 Sup3 a1 One NULL NULL a2 One Two NULL a3 One NULL NULL a4 Two NULL NULL a5 Three NULL NULL Or I can live with this PartNumber Sup1 Sup2 Sup3 a1 One NULL NULL a2 One Two NULL a3 One NULL

Equiv. to Coalesce() in XAML Binding?

若如初见. 提交于 2020-01-10 19:41:09
问题 In SQL I can do this: Select Coalesce(Property1, Property2, Property3, 'All Null') as Value From MyTable If Property1, 2 and 3 are all null, then I get 'All Null' How do I do this in XAML? I tried the following, but no luck: <Window.Resources> <local:Item x:Key="MyData" Property1="{x:Null}" Property2="{x:Null}" Property3="Hello World" /> </Window.Resources> <TextBlock DataContext="{StaticResource MyData}"> <TextBlock.Text> <PriorityBinding TargetNullValue="All Null"> <Binding Path="Property1"

Return first non-null value

人盡茶涼 提交于 2019-12-29 03:58:07
问题 I have a number of functions: String first(){} String second(){} ... String default(){} Each can return a null value, except the default. each function can take different parameters. For example, first could take no arguments, second could take in a String, third could take three arguments, etc. What I'd like to do is something like: ObjectUtils.firstNonNull(first(), second(), ..., default()); The problem is that because of the function call, this does eager evaluation. Where'd I'd like to

Is the null coalesce operator thread safe?

心不动则不痛 提交于 2019-12-28 06:27:15
问题 So this is the meat of the question: Can Foo.Bar ever return null? To clarify, can '_bar' be set to null after it's evaluated as non-null and before it's value is returned? public class Foo { Object _bar; public Object Bar { get { return _bar ?? new Object(); } set { _bar = value; } } } I know using the following get method is not safe, and can return a null value: get { return _bar != null ? _bar : new Object(); } UPDATE: Another way to look at the same problem, this example might be more

Using ISNULL vs using COALESCE for checking a specific condition?

牧云@^-^@ 提交于 2019-12-27 11:07:06
问题 I know that multiple parameters can be passed to COALESCE , but when you want to to check just one expression to see if it doesn't exist, do you use a default or is it a better practice to use ISNULL instead? Is there any performance gain between the two? 回答1: This problem reported on Microsoft Connect reveals some differences between COALESCE and ISNULL : an early part of our processing rewrites COALESCE( expression1, expression2 ) as CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE

Using ISNULL vs using COALESCE for checking a specific condition?

末鹿安然 提交于 2019-12-27 11:06:20
问题 I know that multiple parameters can be passed to COALESCE , but when you want to to check just one expression to see if it doesn't exist, do you use a default or is it a better practice to use ISNULL instead? Is there any performance gain between the two? 回答1: This problem reported on Microsoft Connect reveals some differences between COALESCE and ISNULL : an early part of our processing rewrites COALESCE( expression1, expression2 ) as CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE