null

count(*)、count(1)、count(0)、count(列名)区别

风格不统一 提交于 2020-01-29 12:03:17
1、count(*)、count(1):   count(*)对行的数目进行计算,包含NULL,count(1)这个用法和count(*)的结果是一样的。   如果表没有主键,那么count(1)比count(*)快。表有主键,count(*)会自动优化到主键列上。   如果表只有一个字段,count(*)最快。   count(1)跟count(主键)一样,只扫描主键。count(*)跟count(非主键)一样,扫描整个表。明显前者更快一些。   count(1)和count(*)基本没有差别,但在优化的时候尽量使用count(1)。 2、count(1)、count(列名): (1) count(1) 会统计表中的所有的记录数, 包含字段为null 的记录。 (2) count(字段) 会统计该字段在表中出现的次数,忽略字段为null 的情况。 即不统计字段为null 的记录。 来源: https://www.cnblogs.com/guoyu1/p/12239912.html

剑指offer:合并两个排序的链表

末鹿安然 提交于 2020-01-28 15:35:07
一、题目描述   输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则 二、思路   1.先判断是否是特殊条件     1.1如果两个链表list1、list2都为空,则返回空     1.2如果list1为空则返回list2     1.3如果list2为空则返回list1   2.当两个链表都不为空的时候     将数值小的结点加入链表中   3.当其中一个链表已经遍历完时     直接将剩下的那个链表中的结点依次加入新链表中 三、代码 /* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNode Merge(ListNode list1,ListNode list2) { if(list1==null&&list2==null) return null; if(null==list1) return list2; if(null==list2) return list1; ListNode node = new ListNode(-1); ListNode list = node; while(null!=list1&

LeetCode#236二叉树的最近公共祖先

杀马特。学长 韩版系。学妹 提交于 2020-01-27 14:34:03
题目描述 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先)。” 例如,给定如下二叉树: root = [3,5,1,6,2,0,8,null,null,7,4] 示例 1: 输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 输出: 3 解释: 节点 5 和节点 1 的最近公共祖先是节点 3。 示例 2: 输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4 输出: 5 解释: 节点 5 和节点 4 的最近公共祖先是节点 5。因为根据定义最近公共祖先节点可以为节点本身。 说明: 所有节点的值都是唯一的。 p、q 为不同节点且均存在于给定的二叉树中。 简单分析 用栈保存p,q经历过的节点,然后从栈底开始即为它经历的从根开始到特定节点的遍历顺序,选出最近相同节点即为最近公共祖先。 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode

mysql默认空列的弊端

冷暖自知 提交于 2020-01-27 05:42:24
java后台开发中,设计表时,经常设置字符串类型字段的默认值为null,殊不知字段默认值为null,有哪些性能或存储空间浪费等细微问题。数据量小时,问题不容易发现,但是数据量上亿,细微问题将影响我们的应用性能。 概括 null列在查询的时候容易照成误解 null列在使用count的时候必须要多注意,COUNT(bindTime)不计算null值。 null作为索引需要更多空间,让索引变得复杂 问题一 问题二 新建一个表 CREATE TABLE ` t_car ` ( ` carId ` BIGINT ( 20 ) NOT NULL , ` plateNumber ` VARCHAR ( 50 ) NOT NULL COMMENT '车牌号' , ` memberId ` BIGINT ( 20 ) NOT NULL DEFAULT '0' COMMENT '车主' , ` logoId ` TINYINT ( 6 ) DEFAULT NULL COMMENT '车标' , ` carColor ` TINYINT ( 4 ) DEFAULT NULL COMMENT '车辆颜色' , ` plateColor ` TINYINT ( 4 ) DEFAULT NULL COMMENT '车牌颜色' , ` carType ` TINYINT ( 4 ) NOT NULL

Doctrine 2 OneToMany Cascade SET NULL

半腔热情 提交于 2020-01-26 23:57:43
问题 The error Cannot delete or update a parent row: a foreign key constraint fails. The classes class Teacher { /** *@ORM\OneToMany(targetEntity="publication", mappedBy="teacher") */ protected $publications; } class Publication { /** * @ORM\ManyToOne(targetEntity="Teacher", inversedBy="publications") * @ORM\JoinColumn(name="teacher_id", referencedColumnName="id") */ protected $teacher; } I want What I want is to make it that when you delete a teacher, the id_teacher is modified to NULL. I want to

Doctrine 2 OneToMany Cascade SET NULL

江枫思渺然 提交于 2020-01-26 23:57:12
问题 The error Cannot delete or update a parent row: a foreign key constraint fails. The classes class Teacher { /** *@ORM\OneToMany(targetEntity="publication", mappedBy="teacher") */ protected $publications; } class Publication { /** * @ORM\ManyToOne(targetEntity="Teacher", inversedBy="publications") * @ORM\JoinColumn(name="teacher_id", referencedColumnName="id") */ protected $teacher; } I want What I want is to make it that when you delete a teacher, the id_teacher is modified to NULL. I want to

Oracle Sql 胡乱记

时间秒杀一切 提交于 2020-01-26 11:20:37
/ Oracle查询优化改写 / --1、coalesce 返回多个值中,第一个不为空的值 select coalesce('', '', 's') from dual; --2、order by -----dbms_random.value 生产随机数,利用随机数对查询结果进行随机排序 select * from emp order by dbms_random.value; --指定查询结果中的一列进行排序 select * from emp order by 4; -----order by 中认为null是最大所以null会排在第一或者最后一个 -----可以利用 nulls first 或者 nulls last 对null进行排序处理 select * from emp order by comm nulls first; select * from emp order by comm nulls last; ----- 多列排序,job 降序排列,如果工作一样,按照工号升序排列 select * from emp order by job desc, empno asc; ------依次按照job,empno降序排序 select * from emp order by job, empno desc; ------将empno = 7934 的排在第一位

服务器端表单校验Hibernate Validator

坚强是说给别人听的谎言 提交于 2020-01-26 08:55:17
JSR提供的校验注解: @Null 被注释的元素必须为 null @NotNull 被注释的元素必须不为 null @AssertTrue 被注释的元素必须为 true @AssertFalse 被注释的元素必须为 false @Min(value) 被注释的元素必须是一个数字,其值必须大于等于指定的最小值 @Max(value) 被注释的元素必须是一个数字,其值必须小于等于指定的最大值 @DecimalMin(value) 被注释的元素必须是一个数字,其值必须大于等于指定的最小值 @DecimalMax(value) 被注释的元素必须是一个数字,其值必须小于等于指定的最大值 @Size(max=, min=) 被注释的元素的大小必须在指定的范围内 @Digits (integer, fraction) 被注释的元素必须是一个数字,其值必须在可接受的范围内 @Past 被注释的元素必须是一个过去的日期 @Future 被注释的元素必须是一个将来的日期 @Pattern(regex=,flag=) 被注释的元素必须符合指定的正则表达式 Hibernate Validator提供的校验注解: @NotBlank(message =) 验证字符串非null,且长度必须大于0 @Email 被注释的元素必须是电子邮箱地址 @Length(min=,max=)

In the “ActionBarTabsPager” tutorial, getActivity returns null

五迷三道 提交于 2020-01-25 12:09:42
问题 I have successfully implemented the tutorial: http://developer.android.com/reference/android/support/v4/view/ViewPager.html, as a Tab'ed viewpager activity with fragments on each tab. Each Fragment maintains various UI TextFields etc and everything is working fine with the exception of getActivity(), which returns null when called from any of the fragments. UPDATE: Read this, then please see my own answer below that broadens the scope regarding the cause of this error. Continued: BUT, the

In the “ActionBarTabsPager” tutorial, getActivity returns null

不羁的心 提交于 2020-01-25 12:08:13
问题 I have successfully implemented the tutorial: http://developer.android.com/reference/android/support/v4/view/ViewPager.html, as a Tab'ed viewpager activity with fragments on each tab. Each Fragment maintains various UI TextFields etc and everything is working fine with the exception of getActivity(), which returns null when called from any of the fragments. UPDATE: Read this, then please see my own answer below that broadens the scope regarding the cause of this error. Continued: BUT, the