I want to create a view out of values from different tables. After 2 day of researching without a result I'm now asking for some hints.
This is the table op_id which stores only operationID's
| op_id |
|---------|
| 20180101|
| 20180102|
| ...|
For each op_id in op_id - table exists a own table. For example operations_20180101, operations_20180102, ...
The content of each table looks
| username | data |
|----------|------|
| john | 1239|
| adam | 857|
| ...| ...|
What I try to do is, create a view with the sum(data) of all single tables:
| 20180101 | 3746|
| 20180102 | 4765|
| ...| ...|
To create a simple SQL statement
SELECT * FROM operationview
to get all the data I need.
With
SELECT op_id FROM op_id
I get all my op_id's.
But from there I don't know how to store the result in a variable and query the corresponding table to create a view like
for op_id in (SELECT op_id FROM op_id):
CREATE VIEW overview (SELECT op_id, sum(data) FROM operations_op_id)
All I got from MySQL Documentation looks simple, but doesn't solve my problem. It's the first time I try to do more complex stuff than querying and subquerying. So please excuse my question if the solution is simpler then I can figure out.