第一次查询:
SELECT artikkel_id, liige_id, summa, date, SUM(summa) as papp
FROM rent WHERE date < NOW() group by liige_id
SELECT artikkel_id, maksja_id, summa, timestamp, SUM(summa) as peaks
FROM tulu group by maksja_id
表格中的maksja_id&amp; liige_id是一样的。
点&#34;加入&#34;是的,我可以比较和显示liige_id / maksja_id&#34; papp&#34;和#34;峰值&#34;当papp&lt;时,值和用颜色标记在表行中峰值然后是红色,当=绿色等时
答案 0 :(得分:1)
您希望join
结果集说明
select xx.artikkel_id, l.nimi, xx.summa, xx.`date`, xx.papp,
yy.summa as yysumma, yy.`timestamp`, yy.peaks
from (SELECT artikkel_id, liige_id, summa, date, SUM(summa) as papp
FROM rent WHERE date < NOW() group by liige_id) xx
join (SELECT artikkel_id, maksja_id, summa, timestamp,
SUM(summa) as peaks FROM tulu group by maksja_id) yy
on xx.liige_id = yy.maksja_id
join liige l on l.liige_id = xx.liige_id;
答案 1 :(得分:0)
加入和联盟会产生完全不同的结果。
根据您希望结果如何显示,您可以做什么
Union会给出两者的结果,根据你的例子给你6条记录
SELECT artikkel_id, liige_id as maksja_id, summa, date, SUM(summa) as papp
FROM rent WHERE date < NOW() group by liige_id
union
SELECT artikkel_id, maksja_id, summa, timestamp, SUM(summa) as papp
FROM tulu group by maksja_id
加入将为您提供3条记录而不是上述6条记录的结果。
为此你可以使用@Rahul的回答
就像Rahul一样,我认为你想要加入,不 联盟。
答案 2 :(得分:0)
MySQL有一个SIGN function,它会将其参数(例如xx.papp-yy.peak
)分类为正,零或负。