question regarding comas in lesson 18

+1 elli shnoo · July 15, 2015
Hi Bucky :) 
You are amazing
need to always say first thanks for all your lessons your ACE!!!!!!!!

okay so my question is .........
you showed us the following in the lesson..

SELECT COUNT(*)AS item_count, 
MAX(cost) AS max,
AVG(cost) AS avg
FROM items WHERE seller_id=12

and it all works fine my end
My question is 
how come there are no comas on the last two lines
I tried it with one after third line and got an error
then with coma after every line
but it only works with comas on first two lines ??
Is it that you dont have to put a comma before FROM??
Many thanks if you can answer this for me

Thanks sooooooooooo much
Elli :D

Post a Reply

Replies

Oldest  Newest  Rating
0 Serite Ross · July 16, 2015
I am not sure what that is, but I've noticed on both Java and Python that commas are used to separate certain sets of data while they conjoin others. Like commas in a list separate items so they can be mentioned separately:

food = ["burger", "fries", "pizza"]

Or it separates parameters:

def burgers (variable1, variable2):
        var3 = var1+var2


Or commas can be used to conjoin lines of code such as if you wanted to print a changing statement in Python and have an input at the end. You assign the message to a string, include the changing varible (maybe an increasing number), leave a comma outside the quotes, and writing an input or raw_input statement on the next line lets the user enter information
0 Serite Ross · July 16, 2015
Oops, Im sorry, that somehow posted and i cant remove it or edit it. Anyway in your case it seems as if "SELECT COUNT(*)AS item_count, MAX(cost) AS max, AVG(cost) AS avg" are meant to be together while "FROM items WHERE seller_id=12" is supposed to be excluded. It a separate action, adding a comma on the end of the 3rd line would conjoin all of the statements into one ongoing statement when it's not meant to be together. If you also put a comma on the 4th statement without having anything after that would lead to a syntax error. The commas are part of the syntax.
0 elli shnoo · July 18, 2015
Thanks so much for explaining Serite Yay love it when it all makes sense. Thank you so much for you time, greatly appreciated :D 
  • 1

SQL & Databases

129,985 followers
About

Everything SQL and Databases related in here!

Links
Moderators
Bucky Roberts Administrator