Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

sql - How to combine multiple sqlite queries into one line

Sorry if this question is dumb. i am a beginner and for the past hour i'v been searching the internet for answer and i haven't found one(maybe because i am bad at searching). Anyway, i am writing a query into python so i have to write the entire query into one line but i can't seem to get it right.

SELECT students.first, students.middle, students.last, students.birth
FROM students
WHERE students.house = "Gryffindor"
ORDER BY students.last ASC, students.first ASC
question from:https://stackoverflow.com/questions/65851457/how-to-combine-multiple-sqlite-queries-into-one-line

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are two methods:

'''SELECT students.first, students.middle, students.last, students.birth
FROM students
WHERE students.house = "Gryffindor"
ORDER BY students.last ASC, students.first ASC'''

"SELECT s.first, s.middle, s.last, s.birth FROM students s WHERE s.house = 'Gryffindor' ORDER BY s.last ASC, s.first ASC"

The firsts uses multi-line strings. The second shortens the query a bit, uses single quotes for the embedded string (the SQL standard delimiter), and puts everything on one line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...