문제

SELECT  TO_CHAR(MAX(UnitPrice),'$999D99')AS"Maximum Part Price",
    TO_CHAR(Min(UnitPrice),'$99D99')AS "Minimum Part Price",
    TO_CHAR(AVG(UnitPrice),'$999D99')AS "Average Part Price",
    TO_CHAR((UnitsOnHand*UnitPrice),'$999G999D99') AS "Total Value All Parts"

FROM Part;

Hi, I keep getting a error when I'm trying to do this, all is good till i add the last line.. but i need the last line to do exactly that ...been trying for about 3 hours and its doing my head in

도움이 되었습니까?

해결책

SELECT
  TO_CHAR(MAX(UnitPrice),'$999D99')                 AS"Maximum Part Price",
  TO_CHAR(MIN(UnitPrice),'$99D99')                  AS "Minimum Part Price",
  TO_CHAR(AVG(UnitPrice),'$999D99')                 AS "Average Part Price",
  TO_CHAR(SUM(UnitsOnHand*UnitPrice),'$999G999D99') AS "Total Value All Parts"
FROM Part

;

Try sum function

Example

SELECT
  TO_CHAR(MAX(UnitPrice),'$999D99')                 AS"Maximum Part Price",
  TO_CHAR(MIN(UnitPrice),'$99D99')                  AS "Minimum Part Price",
  TO_CHAR(AVG(UnitPrice),'$999D99')                 AS "Average Part Price",
  TO_CHAR(SUM(UnitsOnHand*UnitPrice),'$999G999D99') AS "Total Value All Parts"
FROM

  (
  SELECT 1 UnitsOnHand, 20 UnitPrice FROM dual UNION
  SELECT 4 UnitsOnHand, 70 UnitPrice FROM dual UNION
  SELECT 3 UnitsOnHand, 10 UnitPrice FROM dual UNION
  select 7 UnitsOnHand, 2 UnitPrice from dual  )

Result

Max       Min     Avg     Sum
$70,00    $2,00   $25,50  $344,00

다른 팁

I would think that this line is causing it to get more row:

TO_CHAR((UnitsOnHand*UnitPrice),'$999G999D99') AS "Total Value All Parts"

Maybe you can change this to:

TO_CHAR(MAX((UnitsOnHand*UnitPrice)),'$999G999D99') AS "Total Value All Parts"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top