Difference of two series in MySQL -


I have a table with MySQL in the following fields: Date, Value, Type.

You can type either export or import. I need a question which gives trade deficit (export-import) for every month Is this possible with a single question?

You should store your date as year / month / day different columns, or easily Any method of linking to a table that lets you do it, otherwise you have to calculate slower on every date column to work over a month, I will leave it as if you have it so far But I will suggest different dates to make this calculation easy ( If you group only for one month, then an additional column that stores the result of EXTRACT (YEAR_MONTH) (case type WHEN 'export' then value ELSE -1 * value ADD) Business _deficit to extract from metable group ( YEAR_MONTH from date)

(I have not tested this, and can be a syntax mix, but this should work)


Comments