我有这个查询工作正常,但我只需要前10名供应商。
然后我需要在“所有其他人”行中记录剩下的所有内容。
如何使用LIMIT 10, 18446744073709551615
SELECT VENDOR_fullname,SUM(POTENTIAL_RECOVERY)
FROM COMPLETE
GROUP BY VENDOR_fullname
ORDER BY SUM(POTENTIAL_RECOVERY) DESC;
答案 0 :(得分:2)
为了记录,我同意@ DamienBlack的评论,但如果必须在一个查询中完成UNION ALL
可以做到这一点:
(
SELECT VENDOR_fullname as name, SUM(POTENTIAL_RECOVERY) as recovery
FROM COMPLETE
GROUP BY VENDOR_fullname
ORDER BY SUM(POTENTIAL_RECOVERY) DESC
LIMIT 10
)
UNION ALL
(
SELECT 'All others' as name, SUM(subtotal) as recovery
FROM
(
SELECT SUM(POTENTIAL_RECOVERY)
FROM COMPLETE
GROUP BY VENDOR_fullname
ORDER BY SUM(POTENTIAL_RECOVERY) DESC
LIMIT 10, 18446744073709551615
) as subtotal;
)
答案 1 :(得分:0)
您可以使用union:
SELECT VENDOR_fullname as anme,SUM(POTENTIAL_RECOVERY)
FROM COMPLETE
GROUP BY VENDOR_fullname
ORDER BY SUM(POTENTIAL_RECOVERY) DESC
LIMIT 10
UNION ALL
SELECT 'All Others' as name,SUM(POTENTIAL_RECOVERY)
FROM COMPLETE
ORDER BY SUM(POTENTIAL_RECOVERY) DESC
LIMIT 10, 18446744073709551615