SQL Playground
Ctrl + Enter to run
GUIDED QUERIES (18)
1. Buscar CFDI por UUIDLvl 1

Encuentra un comprobante específico usando su UUID único.

SELECTWHERE
2. Buscar por Serie/FolioLvl 1

Búsqueda común operativa por folio interno.

SELECTWHEREAND
3. Facturación total por mesLvl 2

Agrupa los totales facturados por mes (YYYY-MM).

GROUP BYSUMDATE
4. Facturación por emisorLvl 2

Total facturado agrupado por RFC de emisor.

JOINGROUP BYORDER BY
5. Facturación por receptorLvl 2

Quiénes son mis mejores clientes (receptores).

JOINGROUP BY
6. Top 10 conceptos más comunesLvl 2

Productos o servicios que más se facturan.

GROUP BYCOUNT
7. CFDI con IVA 16% vs ExentoLvl 2

Comparativa de importes por tipo de impuesto.

GROUP BYSUM
8. Saldo total por emisorLvl 3

Cuánto se debe todavía a cada proveedor (Emisor).

JOINWHEREHAVING
9. Facturas pagadas vs no pagadasLvl 3

Status financiero: Pagado vs Pendiente.

CASEGROUP BY
10. Pagos parcialesLvl 2

Facturas que tienen abonos pero siguen con saldo.

WHEREAND
11. Canceladas últimos 30 díasLvl 2

Auditoría de cancelaciones recientes.

DATEWHERE
12. PUE vs PPD por mesLvl 2

Análisis de flujo de efectivo esperado vs inmediato.

GROUP BYMULTIPLE COLUMNS
13. Formas de pago más usadasLvl 1

Cómo nos pagan (03 Transferencia, 01 Efectivo, etc).

GROUP BY
14. Moneda MXN vs USDLvl 1

Exposición a moneda extranjera.

GROUP BY
15. Buscar por rango de fechasLvl 1

Consulta básica de reportes mensuales.

BETWEENORDER BY
16. JOIN Comprobantes + ConceptosLvl 2

Ver el detalle de líneas de cada factura.

JOIN
17. Promedio de ticket por receptorLvl 3

Cuál es el valor promedio de venta a cada cliente.

AVGHAVING
18. Auditoría de InconsistenciasLvl 3

Facturas donde el total no coincide con subtotal + impuestos (simulado).

MATHWHERE
CFDI SQL LAB
CONNECTING...

SQL Learning Hub

Master SQL concepts using real-world CFDI 4.0 data structures.

1. Tables & Structure

A Table is a collection of related data held in a structured format within a database. It consists of columns (fields) and rows (records).

Primary Key (PK)

A unique identifier for each record in a table. In our cfdi_comprobantes table, the id column is the PK.

Foreign Key (FK)

A field that links to the Primary Key of another table.
Example: emisor_id links to the cfdi_emisores table.

2. Key Concepts in this Lab

SELECT & WHERE

Use SELECT to specify columns and WHERE to filter rows. Essential for finding specific invoices (UUIDs) or dates.

SELECT * FROM cfdi_comprobantes WHERE total > 1000;

JOIN

Combines rows from two or more tables. Use it to see the 'Name' of an Issuer (Emisor) instead of just their ID.

SELECT c.uuid, e.nombre FROM cfdi_comprobantes c JOIN cfdi_emisores e ON c.emisor_id = e.id;

GROUP BY & Aggregates

Groups rows that have the same values into summary rows. Used with COUNT(), SUM(), AVG(). Perfect for monthly reports.

SELECT metodo_pago, SUM(total) FROM cfdi_comprobantes GROUP BY metodo_pago;
Result Grid
0 rows0ms

No results to display. Run a query.

SQL Playground
Ctrl + Enter to run
GUIDED QUERIES (18)
1. Buscar CFDI por UUIDLvl 1

Encuentra un comprobante específico usando su UUID único.

SELECTWHERE
2. Buscar por Serie/FolioLvl 1

Búsqueda común operativa por folio interno.

SELECTWHEREAND
3. Facturación total por mesLvl 2

Agrupa los totales facturados por mes (YYYY-MM).

GROUP BYSUMDATE
4. Facturación por emisorLvl 2

Total facturado agrupado por RFC de emisor.

JOINGROUP BYORDER BY
5. Facturación por receptorLvl 2

Quiénes son mis mejores clientes (receptores).

JOINGROUP BY
6. Top 10 conceptos más comunesLvl 2

Productos o servicios que más se facturan.

GROUP BYCOUNT
7. CFDI con IVA 16% vs ExentoLvl 2

Comparativa de importes por tipo de impuesto.

GROUP BYSUM
8. Saldo total por emisorLvl 3

Cuánto se debe todavía a cada proveedor (Emisor).

JOINWHEREHAVING
9. Facturas pagadas vs no pagadasLvl 3

Status financiero: Pagado vs Pendiente.

CASEGROUP BY
10. Pagos parcialesLvl 2

Facturas que tienen abonos pero siguen con saldo.

WHEREAND
11. Canceladas últimos 30 díasLvl 2

Auditoría de cancelaciones recientes.

DATEWHERE
12. PUE vs PPD por mesLvl 2

Análisis de flujo de efectivo esperado vs inmediato.

GROUP BYMULTIPLE COLUMNS
13. Formas de pago más usadasLvl 1

Cómo nos pagan (03 Transferencia, 01 Efectivo, etc).

GROUP BY
14. Moneda MXN vs USDLvl 1

Exposición a moneda extranjera.

GROUP BY
15. Buscar por rango de fechasLvl 1

Consulta básica de reportes mensuales.

BETWEENORDER BY
16. JOIN Comprobantes + ConceptosLvl 2

Ver el detalle de líneas de cada factura.

JOIN
17. Promedio de ticket por receptorLvl 3

Cuál es el valor promedio de venta a cada cliente.

AVGHAVING
18. Auditoría de InconsistenciasLvl 3

Facturas donde el total no coincide con subtotal + impuestos (simulado).

MATHWHERE
CFDI SQL LAB
CONNECTING...

SQL Learning Hub

Master SQL concepts using real-world CFDI 4.0 data structures.

1. Tables & Structure

A Table is a collection of related data held in a structured format within a database. It consists of columns (fields) and rows (records).

Primary Key (PK)

A unique identifier for each record in a table. In our cfdi_comprobantes table, the id column is the PK.

Foreign Key (FK)

A field that links to the Primary Key of another table.
Example: emisor_id links to the cfdi_emisores table.

2. Key Concepts in this Lab

SELECT & WHERE

Use SELECT to specify columns and WHERE to filter rows. Essential for finding specific invoices (UUIDs) or dates.

SELECT * FROM cfdi_comprobantes WHERE total > 1000;

JOIN

Combines rows from two or more tables. Use it to see the 'Name' of an Issuer (Emisor) instead of just their ID.

SELECT c.uuid, e.nombre FROM cfdi_comprobantes c JOIN cfdi_emisores e ON c.emisor_id = e.id;

GROUP BY & Aggregates

Groups rows that have the same values into summary rows. Used with COUNT(), SUM(), AVG(). Perfect for monthly reports.

SELECT metodo_pago, SUM(total) FROM cfdi_comprobantes GROUP BY metodo_pago;
Result Grid
0 rows0ms

No results to display. Run a query.