mysql表user中有字段主键id,字段age.我现在想修改age=(id-1)5+1;

mysql表user中有字段主键id,字段age.我现在想修改age=(id-1)5+1;,第1张

update user set age=cast((id-1)/5+1 as unsigned)

有id, name两个字段,其中id是主键,或者是唯一的字段

REPLACE t1 (id, ', name) VALUES(1, name) VALUES(1:id不存在是就插入一条, 'alan')

多条情况:

REPLACE t1 (idalan'), (2, 'lstt',存在是就自动删除原来的), (3, 'ssnl')

原理是,再插入新的

所以假设两个表结构完全相同。不同的话就需要指明所有的列。

Replace table2 Select * From table1

假设表名叫t1

select top 1 id,name,age from 表 order by age desc

按照年龄倒序排序,然后取第一条。

考虑可能有多人年龄相同,如果都需取出,可以这样写:

select id,name,age from 表 where age=(select max(age) from 表)

Create table Student (ID CHAR(30) PRIMARY KEY, NAME CHAR(20) NOT NULL, AGE NUMBER(5) DEFAULT 0)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8632964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-19
下一篇 2023-04-19

发表评论

登录后才能评论

评论列表(0条)

保存