Create tables from mysql queries

0

How could a table be created from several queries in mysql . I have the following questions:

--selecciona tipo gasto sin repetir un registro --- 
SELECT DISTINCT tipo_gasto FROM factura'

number of records of that variable

SELECT COUNT(tipo_gasto) cantidad FROM factura WHERE tipo_gasto = 'vivienda'

Add the columns type_expend

SELECT ROUND(SUM(valor_base),2) total FROM factura WHERE tipo_gasto = 'VIV'

Is it possible to create a table based on these queries?

    
asked by Javtronic 15.06.2017 в 01:54
source

3 answers

1

In that case, you only need to group by type_expenditure. Try this way:

SELECT tipo_gasto, count(tipo_gasto), ROUND(SUM(valor_base),2) 
    FROM factura GROUP BY tipo_gasto
    
answered by 15.06.2017 / 04:14
source
0

Indeed you can create temporary tables in the following way:

CREATE TEMPORARY TABLE nombreTablaTemporal aqui_tu_consulta;

These temporary tables can be saved

If you have any questions, please comment.

Luck.

Update

An approximation to your serious problem:

CREATE TEMPORARY TABLE temporal SELECT tipo_gasto, count(tipo_gasto), ROUND(SUM(valor_base),2) FROM factura WHERE tipo_gasto = 'VIV' AND tipo_gasto = 'vivienda';

SELECT * FROM temporal;

And this would be to consult for all types of expenses:

CREATE TEMPORARY TABLE temporal SELECT tipo_gasto, count(tipo_gasto), ROUND(SUM(valor_base),2) FROM factura GROUP BY tipo_gasto;

SELECT * FROM temporal;
    
answered by 15.06.2017 в 02:08
-1

IN SQL YOU CAN USE THE CREATE TABLE INSTRUCTION

SYNTAX:

CREATE TABLE < NOMBRE DE LA TABLA > (

    // COLUMNAS Y SU TIPO DE DATO
    < NOMBRE DE LA COLUMNA > < TIPO DE DATO >

    // LLAVE PRIMARIA
    PRIMARY KEY(< NOMBRE DE LA COLUMNA >)

);
    
answered by 08.11.2017 в 05:08