1.情景展示 现在有两者表,表1中的主键id字段和表2的index_id相对应.如何删除两表非关联数据? 2.解决方案 --第1步 delete from VIRTUAL_CARD t where t.index_id not in (select id from PRIMARY_INDEX); --第2步 delete from PRIMARY_INDEX t where t.id not in (select index_id from VIRTUAL_CARD); 说明: 如果in()
如下:一张订单表多个字段关联用户表: 1.链表查询 SELECT cu.id AS 'id',cu.version AS 'version',cu.cid AS 'cid',cu.uid AS 'uid',cu.shopName AS 'shopName',cu.address AS 'address', cu.totalPrice AS 'totalPrice',cu.orderType AS 'orderType', cu.state AS 'state',cu.cCreateTime AS
背景: A表.B表两表关联,关联出来的结果里B表有不止一条,需求是只要B表结果中的某一条(按某字段排序) 首先想到了直接写个带排序的子查询去匹配外围的值,从这个结果集中只要第一条,但是经过验证发现,里边的条件是获取不到外层的值的,因此此方案不可行. 经过百度,发现 row_number() over函数可用,以下是数据环境及结果. 创建数据环境 )); insert into A values('alan'); insert into A values('Alee'); insert into
1.MySql获取表结构信息 SELECT TABLE_NAME, TABLE_COMMENT FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = 'dm' -- dm 是数据库名称,需替换 ORDER BY TABLE_NAME; 2.MySql获取字段信息 SELECT TABLE_NAME AS 'tableName', COLUMN_NAME AS 'columnName', COLUMN_COMMENT AS 'columnCom
create table Uc_t_Department3 as (select * from Uc_t_Department where 1=2);insert into Uc_t_Department3 select * from Uc_t_Department; -------------------------------------------------------------------------------------------------------------------