Greeting everyone. This is my first post in this forum. I'm not a MySQL expert, in the matter of fact, I have no idea what MySQL is. Some company made a series of question that enables you to win a prize at the end. One of their questions is a MySQL problem. I'd be grateful if someone can provide the answer. Thanks in advance! Consider the following MySQL table: CREATE TABLE history ( ORDER_ID int(11) NOT NULL auto_increment, CUSTOMER_ID int(11) NOT NULL, ORDER_DATE date NOT NULL, HT int(11) NOT NULL, TVA int(11) NOT NULL, TOTAL int(11) NOT NULL, PRIMARY KEY (ORDER_ID) ); Applications accessing this table, run just the following queries on it: - Insert a new record for a new order: Example: INSERT INTO history(CUSTOMER_ID, ORDER_DATE, HT, TVA, TOTAL) VALUES (436, NOW(), 310, 31, 341); - Retrieve all records for a specific customer: Example: SELECT * FROM history WHERE CUSTOMER_ID = 767; - Calculate the sum of totals for a specific customer between 2 specific dates: Example: SELECT SUM(TOTAL) FROM history WHERE CUSTOMER_ID = 7675 AND ORDER_DATE < '2012-12-31' AND ORDER_DATE > '2011-12-31'; - Retrieve customers and the number of times these customers completed orders with a total bigger than a specific number: Example: SELECT CUSTOMER_ID, COUNT(*) FROM history WHERE TOTAL > 10000 GROUP BY CUSTOMER_ID; - Retrieve the record with a specific order_id Example: SELECT * FROM history WHERE ORDER_ID = 4567; What is the optimal way to create the indexes on this table? Explain why. (Provide the SQL statements required to create those indexes.)
all I can see on these queries is that you need to create index on CUSTOMER_ID, why? first you need to know what index is and why it's helpful in summary we create index to speed up the query result and in these queries you need to create index on CUSTOMER_ID because in all queries mostly what is being uses is CUSTOMER_ID and in SQL you created index on WHERE condition it's just a summary index is big topic and if you never used MySQL that or even database it's too hard for you to understand hope it helps cheers