如何在MariaDB中按顺序返回包含空值的行。
我有一个ID列表,我想查询,但实际结果不是我所期望的。
记录05.173不存在,但我需要空行按顺序排列。
这可能吗?
SELECT b.*, a.sia_id
FROM (
SELECT '02.352' AS sia_id
UNION ALL
SELECT '05.173' AS sia_id
UNION ALL
SELECT '02.352' AS sia_id
UNION ALL
SELECT '05.173' AS sia_id
UNION ALL
SELECT '05.451' AS sia_id
) AS a
LEFT JOIN estoques AS b
USING (sia_id) order by `validade` asc
当前结果
[
{null},
{null},
{siaId:'02.352', ...},
{siaId:'02.352', ...},
{siaId:'05.451', ...}
]
预期结果
[
{siaId:'02.352', ...},
{null},
{siaId:'02.352', ...},
{null},
{siaId:'05.451', ...},
]
1条答案
按热度按时间up9lanfz1#
您可以将排序属性添加到派生表:
结果集中没有明确排序依据的任何顺序都应视为重合。