Scarpah600 / BancoDeDados

0 stars 0 forks source link

BANCO DE DADOS ( FUNCTION) #9

Open Scarpah600 opened 6 years ago

Scarpah600 commented 6 years ago

CREATE FUNCTION TOTALGUSTAVOS () RETURNS @VALORES TABLE (ID_USUARIO INT,VALORES REAL) AS BEGIN INSERT @VALORES SELECT CA.ID_USUARIO,SUM(CA.QUANTIDADE * CO.VALOR) AS VALOR FROM MOEDAS.CARTEIRA AS CA INNER JOIN MOEDAS.COTACAO AS CO ON CO.ID_MOEDA = CA.ID_MOEDA WHERE CO.DATAHORA = (SELECT MAX(DATAHORA) FROM MOEDAS.COTACAO AS CO2 WHERE CO2.ID_MOEDA = CO.ID_MOEDA)

    GROUP BY CA.ID_USUARIO
    RETURN

END SELECT * FROM TOTALGUSTAVOS()