数组与SQL-第4天

LeetCode

  • 题目: 最大子数组和

给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。子数组 是数组中的一个连续部分。

  •  代码
	public static void main(String[] args) {
		int[] nums = { -1,-2};
		System.out.println(maxSubArray(nums));
	}

	public static int maxSubArray(int[] nums) {
		int pre = 0;
		int max = nums[0];
        for (int x : nums) {
            pre = Math.max(pre + x, x);
            max = Math.max(max, pre);
        }
        return max;
	}

nowcoder

  • 题目: 在last_update后面新增加一列名字为create_date

存在actor表,包含如下列信息:

CREATE TABLE  actor  (
   actor_id  smallint(5)  NOT NULL PRIMARY KEY,
   first_name  varchar(45) NOT NULL,
   last_name  varchar(45) NOT NULL,
   last_update  datetime NOT NULL);

现在在last_update后面新增加一列名字为create_date, 类型为datetime, NOT NULL,默认值为'2020-10-01 00:00:00'。 【知识点

①添加字段[默认在最后添加]

ALTER TABLE <表名> ADD <字段名> <字段类型> [约束条件] 

② 添加字段[指定位置添加]

#在某个字段后面添加
ALTER TABLE <表名> ADD <字段名> <字段类型> [约束条件] AFTER <已存在的字段>
#在开头添加
ALTER TABLE <表名> ADD <字段名> <字段类型> [约束条件] FIRST

③添加字段时设置默认值

ALTER TABLE <表名> ADD <字段名> <字段类型> [约束条件] DEFAULT <值>
  • 代码
ALTER TABLE actor ADD create_date datetime NOT NULL 
DEFAULT '2020-10-01 00:00:00' 
AFTER last_update

猜你喜欢

转载自blog.csdn.net/weixin_46899412/article/details/123609782