MySQL Forums
Forum List  »  Newbie

Re: how to insert data from an existing table, to another (empty) existing table on mysql?
Posted by: Peter Brawley
Date: March 13, 2018 09:17AM

Screenshots aren't necessary.

A table isn't a real table unless it has a primary key. Your date column values aren't unique so it's not a candidate key.

SQL isn't good at reporting data that isn't there. To report per month when there may be missing months in the data, you need a calendar table, see that topic at https://www.artfulsoftware.com/queries.php.

Once you have the calendae table, you can write a query like ...

select month(datecolumn) as mo, sum(...)
from tbl
group by mo;

... to produce your per-month report. Saving the result won't accomplish much though---as soon as the source data changes, the saved result is wrong. Usually it's better to save the sql and run the saved sql whenever the result is needed.

Options: ReplyQuote


Subject
Written By
Posted
Re: how to insert data from an existing table, to another (empty) existing table on mysql?
March 13, 2018 09:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.