mysql5.7计算列的一些使用实例

CREATE TABLE `fa_parent_goods`  (
  `id` mediumint(11) NOT NULL AUTO_INCREMENT COMMENT '商品id',
  `goods_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '商品名称',
  `images` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '产品图片',
  `content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '详情',
  `qun_id` int(10) NULL DEFAULT NULL COMMENT '社群id',
  `time_json` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '预定时间设置',
  `create_time` int(10) NULL DEFAULT NULL,
  `is_pg` tinyint(1) NULL DEFAULT 0 COMMENT '是否拼购',
  `audit` tinyint(1) NULL DEFAULT 0 COMMENT '审核 0待审核1通过 2驳回',
  `update_time` int(10) NULL DEFAULT NULL,
  `sales` smallint(5) NULL DEFAULT 0 COMMENT '销量',
  `min_tgprice` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '最小团购价',
  `min_pgprice` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '最小拼购价',
  `min_price` decimal(10, 2) GENERATED ALWAYS AS (least(`min_tgprice`,`min_pgprice`)) VIRTUAL NULL
  `validate_switch` tinyint(4) NULL DEFAULT NULL COMMENT '是否设置有效时间',

  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '商品表' ROW_FORMAT = Compact;

SET FOREIGN_KEY_CHECKS = 1;


ALTER TABLE `yz`.`fa_parent_goods_copy1` 
ADD COLUMN `min_price` decimal(10, 2) GENERATED ALWAYS AS (least(`min_tgprice`,`min_pgprice`)) VIRTUAL NULL


CREATE TABLE log_sync_plan_data(
    planLogId BIGINT PRIMARY KEY NOT NULL auto_increment,
    syncType int NOT NULL DEFAULT 0,
    tablesCnt int NOT NULL,
    finishedCnt int NOT NULL DEFAULT 0,
    beginTime datetime NOT NULL DEFAULT NOW(),
    endTime datetime NOT NULL DEFAULT '1900-01-01',
    elapsedSeconds INT generated always AS (case when endTime<beginTime then -1 ELSE timestampdiff(SECOND,endTime,beginTime) END) VIRTUAL,
    errMsg varchar(4000) NULL,
    success INT generated always AS( case when endTime<beginTime OR ifnull(errMsg,'')<>'' OR tablesCnt<>finishedCnt then 0 else 1 end) VIRTUAL
);

 

发布了56 篇原创文章 · 获赞 16 · 访问量 9万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览