So, I'm trying to assign some SQL to a variable which will later be executed in the code. I also want to include a varible inside the SQL. I am only allowed to code over 80 characters and then I have been told to use a black slash, now this causes a problem. Hopefully this better explains it:

Current code-

sql_query = """"SELECT A1.value Value, COUNT(A1.value) "Frequency",
A1.category Category'
FROM popularity A1
WHERE Category = "books"
GROUP BY A1.value"""

I need to insert a varible here:

WHERE Category = category

Now that I think about it I might just assign each line to a variable but it's not aesthetically pleasing.

5 Years
Discussion Span
Last Post by ineedhelpasap

I have a solution which I'm half-heartedly happy with:

sql_query = 'SELECT A1.value Value, COUNT(A1.value)' + '"Frequency"'
sql_query = sql_query + ' , A1.category Category'
sql_query = sql_query + ' FROM popularity A1'
sql_query = sql_query + ' WHERE Category = ' + test + ' GROUP BY A1.value'

New solution:

sql_query = 'SELECT A1.value Value, COUNT(A1.value)' + '"Frequency"' \
    + ', A1.category Category' + ' FROM popularity A1' + ' WHERE Category = ' \
    + test + ' GROUP BY A1.value'

^ That one looks better, I think it might be the best I can get. Though, I'll still take suggestions.

Edited by ineedhelpasap: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.