select sum(a.data-b.data)from(select data,time from 表名 where id=1) a,(select data,time from 表名 where id=2) bwhere a.time=b.time 你看是这个意思吗?不过这样的话数据要求比较严格,同一时间id为1为2的只能有1条,多了会出错,但是大概意思就是上边所写 ...
oracle可以通过rowid来删除重复记录,mysql需要这个表有主键可以删出多余的,留一条,如果没有,需要创建临时表,再去重后处理。
mysql同一张表中两个字段 关联另一张表的相同字段 查询出两个值select*fromtablewhereid=parent_id;
在MySQL数据库中,可以使用UPDATE语句结合SELECT语句来修改一个表中的数据,使其与另一个表中的数据相匹配。例如,可以使用这样的语句:UPDATE b,a set num3=a.num1-a.num2 where b.name1=a.name2。这里,我们从表a中获取数据并将其应用于表b,根据name1和name2之间的匹配进行计算。另一个例子...
create table pk (id int not null,one varchar(20),two varchar(20));1 select count(one) as num1 from pk;2 select count(two) as num2 from pk where two not in(select one from pk);