mysql - 如何从另一个MySQL中减去一行

标签 mysql sql

鉴于附上的表格

enter image description here

如何找到每天销售的 Mac 和 Windows 之间的差异。 有人可以解释一下逻辑吗

最佳答案

INNER JOIN 可以完成这项工作。

SELECT 
WindowsTable.Date,
ABS(WindowsTable.Sold - MacTable.Sold) absoluteDifference 
FROM
(SELECT 
*
FROM producttable
WHERE Products = 'Windows') WindowsTable

INNER JOIN 

(
SELECT 
*
FROM producttable
WHERE Products = 'Mac' ) MacTable

ON WindowsTable.Date = MacTable.Date;

DEMO HERE

关于mysql - 如何从另一个MySQL中减去一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36416549/

相关文章:

mysql - 查询具有一个值的两个组合字段

MySQL 5 : How to find the peak of customers during working time

sql - Oracle 是否为 Number 数据类型存储尾随零?

php - Laravel 计数中的行数有很多关系

mysql - 从 MySQL 复制到 MongoDB 时连接被强制关闭

mysql - 选择至少包含搜索查询的行

php - 只允许在文本区域中换行

php - 从时间戳最新的表中选择

sql - 是否有理由不在 Oracle 中使用 View ?

php - mysqli_real_escape_string 似乎不起作用