Pergunta

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

Foi útil?

Solução

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

Outras dicas

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"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top