All fields in the SELECT statement must be included in the GROUP statement? I want to group by ColumnName and sum everything else. How do I do this without listing all the fields explicitly in the SELECT statement?
The problem is kind of unique. I have a table whose column names can change from day to day. Furthermore, there are many, many columns. So, it is not practical to list all the column names, and I tried to cheat and use “*”. Probably, I need to figure out how to dynamically create the query, or more likely, I will just dump everything into my computer and use some method that I do know…
I’ve always avoided using SQL to a fault. I’ve been trying to improve my Excel, Access, PowerPivot skills. But SQL seems valuable to learn – so maybe it’s worth struggling with.
^Access uses SQL so really learning one is learning the other. I have a general sense of it and if I need to do something I can usually review a book and figure it out. The thing that keeps me from using it more is that no one else in my group uses it. If it’s just me using it, then operational risk people will come down on us for not having a back up.
The benefit of a databaase (whether SQL or some other) is that you don’t have to read all the data into memory at once. So if I’m doing an analysis of 5000 stocks and a bunch of data points for each one over time, I don’t have to worry about my computer running out of memory if I start doing a bunch of operations on everything. If you’re not worried about memory, you can usually hack together something in excel that can approximate whatever it is that you could have used a proper database for.
It seems to me that maybe the answer is to load the full table into memory and do the addition in the code that receives the data from SQL, like Python, Java, or even C++. If you aren’t going to get a zillion rows, that may be your best solution.
That was my initial response, but I held back because if someone knew how to do it in SQL, I wanted to see how to do it.
I’ve relearned and forgotten SQL so many times I don’t know if I should be embarrassed, or proud…