从由其来自的表中标识的联盟中选择最新记录

时间:2018-03-23 03:07:03

标签: mysql sql max union

请参阅下文。

const a = { choo: 'choo' }
const b = [ { foo: 'bar' }, { foo: 'baz' }, { foo: 'foo' } ]

const c = b.map((item) => Object.assign(item, a));

console.log(c);
console.log(b);

我想要过滤什么

my Data Set:
tsl dte     | sales | inserton |Mode
03-01-18    |1000   | 03-01-18 | A
03-01-18    |2000   | 03-05-18 | M
03-02-18    |0.00   | 03-02-18 | A
03-02-18    |1500   | 03-08-18 | A
03-03-18    |0.00   | 03-03-18 | A
03-03-18    |0.00   | 03-03-18 | M
03-03-18    |0.00   | 03-03-18 | M
03-03-18    |1500   | 03-08-18 | M
03-04-18    |2600   | 03-04-18 | A

如何使用tsl dte | sales | inserton |Mode 03-01-18 |2000 | 03-05-18 | M 03-02-18 |1500 | 03-08-18 | A 03-03-18 |1500 | 03-08-18 | M 03-04-18 |2600 | 03-04-18 | A 两个表格来发送最新记录:

UNION(自动发送)

SalesDetail(手动发送)。

我突出显示了我想要的行:

enter image description here

1 个答案:

答案 0 :(得分:0)

以下是在MySQL中执行此操作的一种快捷方式:

SELECT *
FROM
(
    SELECT *, 'SalesDetail' AS source
    FROM SalesDetail
    UNION ALL
    SELECT *, 'SalesDetailManual'
    FROM SalesDetailManual
) t
ORDER BY insertOn DESC
LIMIT 1;

请注意,我在两个子查询中添加了一个计算列source,以跟踪每个表的来源。