我需要创建一个查询,从名为INV_NUM
的表中输出INV_AMOUNT
,AVG_INV
,DIFF
和INVOICE
。< / p>
到目前为止,我有这个:
SELECT INV_NUM,
INV_AMOUNT,
(SELECT AVG(INV_AMOUNT) FROM INVOICE) AS AVG_INV
FROM INVOICE;
我是sql的新手,我正试图弄清楚如何制作
(SELECT SUM(INV_AUMOUNT - AVG(INV_AMOUNT) FROM INVOICE) AS DIFF
的工作。我已经搜索了一个解决方案,但无法实现有效的方法。感谢您的任何帮助。谢谢。
答案 0 :(得分:0)
你似乎想要这样的东西:
SELECT i.INV_NUM, i.INV_AMOUNT, ai.avg_inv_amount,
(i.INV_AMOUNT - ai.avg_inv_amount) as diff
FROM INVOICE as i,
(SELECT AVG(INV_AMOUNT) as avg_inv_amount FROM INVOICE) as ai;