CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] [DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }] [SQL SECURITY { DEFINER | INVOKER }] VIEW [IF NOT EXISTS] view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] CHECK OPTION]
Где ALGORITHM это алгоритм хранения вьюшки.
Где DEFINER определяет кто создал вьюшку
Где SQL SECURITY это доступ чтения вьюшки
column_list список колонок выводимых из вьюшки, необходим для лучшей оптимизации
WITH * CHECK OPTION, тип данных, так-же требуется для оптимизации.
CREATE OR REPLACE ALGORITHM = MERGE DEFINER = CURRENT_USER SQL SECURITY INVOKER VIEW `alchemy_by_days` (`date`,`earth`,`air`,`water`,`fire`,`life`,`shadow`) AS SELECT DATE(FROM_UNIXTIME(ep.`timestamp`)) AS `date`, SUM(IF(ep.type = "earth", ep.price, 0)) AS `earth`, SUM(IF(ep.type = "air", ep.price, 0)) AS `air`, SUM(IF(ep.type = "water", ep.price, 0)) AS `water`, SUM(IF(ep.type = "fire", ep.price, 0)) AS `fire`, SUM(IF(ep.type = "life", ep.price, 0)) AS `life`, SUM(IF(ep.type = "shadow", ep.price, 0)) AS `shadow` FROM `etheral-prices` ep GROUP BY ep.`timestamp` ORDER BY ep.`timestamp` DESC;