Coder Social home page Coder Social logo

defontana_back's Introduction

Back defontana

El siguiente repositiorio contiene la solucion a ls preguntas realizadas.

El back fue construirdo en python y docker por lo cual si desea ejecutarlo ejecute los comandos:

docker build -t defontana_back .  
docker run --name backDefontana -p 5000:5000 defontana_back:latest 

por fines de lograr el reto y entender la base de datos se ha realizado un diagrama actualizado segun lo encontrado en la base de datos:

alt text

adicionalmente para complir con la segunda parte acontinuacion encontrara los sql para cada seccion:

• El total de ventas de los últimos 30 días (monto total y cantidad total de ventas).

SELECT 
    COUNT(*) as total_ventas, 
    SUM(Total) as monto_total_ventas
FROM 
    Prueba.dbo.Venta
WHERE 
    Fecha >= DATEADD(dd, -30, GETDATE()) 
    AND Fecha < GETDATE();

• El día y hora en que se realizó la venta con el monto más alto (y cuál es aquel monto).

SELECT TOP 1 Fecha, Total
FROM Prueba.dbo.Venta
ORDER BY Total DESC;

• Indicar cuál es el producto con mayor monto total de ventas. El total de ventas de un producto se encuentra en la tabla VentaDetalle columna TotalLinea.

SELECT TOP 1 p.*, SUM(vd.TotalLinea) as monto_total_ventas
FROM Prueba.dbo.Producto p
JOIN Prueba.dbo.VentaDetalle vd ON p.ID_Producto = vd.ID_Producto
GROUP BY p.ID_Producto, p.Nombre, p.Codigo, p.ID_Marca, p.Modelo, p.Costo_Unitario
ORDER BY monto_total_ventas DESC;

• Indicar el local con mayor monto de ventas.

SELECT TOP 1 l.*, SUM(v.Total) as monto_total_ventas
FROM Prueba.dbo.Local l
JOIN Prueba.dbo.Venta v ON l.ID_Local = v.ID_Local
GROUP BY l.ID_Local, l.Nombre, l.Direccion
ORDER BY monto_total_ventas DESC;

• ¿Cuál es la marca con mayor margen de ganancias? El margen de ganancias de un producto está dado por (Cantidad vendida * Precio unitario) - (Cantidad vendida * Costo).

SELECT TOP 1 m.*, SUM((vd.Cantidad * vd.Precio_Unitario) - (vd.Cantidad * p.Costo_Unitario)) as margen_ganancias
FROM Prueba.dbo.Marca m
JOIN Prueba.dbo.Producto p ON m.ID_Marca = p.ID_Marca
JOIN Prueba.dbo.VentaDetalle vd ON p.ID_Producto = vd.ID_Producto
GROUP BY m.ID_Marca, m.Nombre
ORDER BY margen_ganancias DESC;

• ¿Cómo obtendrías cuál es el producto que más se vende en cada local?

WITH VentasPorLocal AS (
    SELECT v.ID_Local, vd.ID_Producto, SUM(vd.Cantidad) as total_vendido
    FROM Prueba.dbo.Venta v
    JOIN Prueba.dbo.VentaDetalle vd ON v.ID_Venta = vd.ID_Venta
    GROUP BY v.ID_Local, vd.ID_Producto
)
SELECT l.*, p.*, vp.total_vendido
FROM Prueba.dbo.Local l
JOIN VentasPorLocal vp ON l.ID_Local = vp.ID_Local
JOIN Prueba.dbo.Producto p ON vp.ID_Producto = p.ID_Producto
WHERE vp.total_vendido = (
    SELECT MAX(total_vendido)
    FROM VentasPorLocal
    WHERE ID_Local = l.ID_Local
);

defontana_back's People

Contributors

botoom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.