r/mysql • • Jan 07 '25

troubleshooting Trouble Creating Table Using Select Statement

Here is my query:

CREATE TABLE `product line avg`

SELECT `walmart sales data.csv`.`Product line`, `walmart sales data.csv`.AVG(Total)

FROM `walmart sales data.csv`

GROUP BY `Product Line`;

MySQL Workbench just says I have an error in my syntax, and so I should check the manual for my server version. Below is a link to a google drive folder with a csv file which contains the data in my table, in case that helps. I looked at the documentation for creating tables with info from a select statement, but even copying different syntax every which way didn't seem to get this to work. The syntax above is my closest guess, but of course doesn't work. Please let me know how these are done generally, and what I can do to fix mine.

https://drive.google.com/drive/folders/1kmtPvUZm-bDWSv6nT-SkZzEQVOmDkKtb?usp=sharing

0 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/Flamelix Jan 08 '25

Walmart Sales Data.csv is just the name for my table. Just a select query by itself works with that name. Sorry, I should have changed the name from when I imported the data into a table.

1

u/Outdoor_Releaf Jan 08 '25

Got it. Both u/r3pr0b8 and r/Qualabel have identified the problem you are having.

If you want to change the names of the table and attributes, you can right click on the table name in schemas and then choose ALTER TABLE. Just type the new name where the old name was and click Apply. I like to avoid blanks in the names of things, so I don't need the back-quotes.

2

u/Flamelix Jan 08 '25

I used this to change the names, thank you for the advice :)