本文整理汇总了Python中Db.Db.query方法的典型用法代码示例。如果您正苦于以下问题:Python Db.query方法的具体用法?Python Db.query怎么用?Python Db.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db.Db
的用法示例。
在下文中一共展示了Db.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Db
# 需要导入模块: from Db import Db [as 别名]
# 或者: from Db.Db import query [as 别名]
import sqlite3
from Db import Db
if __name__ == '__main__':
db = Db('test.db')
db.execue_script('xjadralci.sql')
comm = "SELECT ime, rating FROM Jadralec j WHERE rating%2=0"
k = db.query(comm)
print(k)
comm = "SELECT c1.ime, c1.cid FROM Coln c1, Coln c2 WHERE c1.ime = c2.ime AND c1.cid != c2.cid"
k = db.query(comm)
print(k)
comm = "SELECT c.ime, c.dolzina, j.starost FROM Coln c " \
"JOIN Rezervacija r USING(cid) " \
"JOIN Jadralec j USING(jid) " \
"WHERE c.dolzina > 35 " \
"AND j.starost > 35"
k = db.query(comm)
print(k)
comm = "SELECT c.ime, c.dolzina, j.starost FROM Coln c, Rezervacija r, Jadralec j " \
"WHERE c.cid = r.cid " \
"AND r.jid = j.jid " \
"AND c.dolzina > 35 "\
"AND j.starost > 35"
k = db.query(comm)
print(k)
comm = "SELECT DISTINCT j.ime, r.dan FROM Jadralec j LEFT JOIN Rezervacija r"
示例2: Db
# 需要导入模块: from Db import Db [as 别名]
# 或者: from Db.Db import query [as 别名]
import sqlite3
from Db import Db
if __name__ == '__main__':
db = Db('rating.db')
db.execue_script('rating.sql')
comm1 = "SELECT Movie.title FROM Movie WHERE director = 'Steven Spielberg'"
a = db.query(comm1)
print(a)
print("2. Find all years that have a movie that received a rating of 4 or 5 "
"and sort them in increasing order.")
comm1 = "SELECT DISTINCT Movie.year FROM Movie, Rating " \
"WHERE Movie.mID = Rating.mID " \
"AND Rating.stars >= 4 " \
"ORDER BY Movie.year ASC"
a = db.query(comm1)
print(a)
print("3. Find the titles of all movies that have no ratings.")
comm1 = "SELECT Movie.title FROM Movie " \
"WHERE NOT EXISTS "\
"(SELECT * FROM Rating "\
"WHERE Movie.mID = Rating.mID)"
a = db.query(comm1)
print(a)
print("4. Some reviewers didn't provide a date with their rating. "
"Find the names of all reviewers who have "
"ratings with a NULL value for the date.")
示例3: Db
# 需要导入模块: from Db import Db [as 别名]
# 或者: from Db.Db import query [as 别名]
import sqlite3
from Db import Db
if __name__ == '__main__':
db = Db('test.db')
db.execue_script('xjadralci.sql')
comm = 'SELECT ime FROM Jadralec WHERE rating % 2 = 0'
even = db.query(comm)
print(even)
comm = 'SELECT ime FROM Jadralec WHERE rating % 2 != 0'
odd = db.query(comm)
print(odd)
comm = 'SELECT * FROM Coln c1, Coln c2 WHERE (c1.ime = c2.ime) AND (c1.cid != c2.cid)'
equal_name = db.query(comm)
print(equal_name)
comm = 'SELECT * FROM Coln c JOIN Rezervacija r USING(cid) JOIN Jadralec j' \
' USING(jid) WHERE c.dolzina>35 and j.starost<35'
boat_name = db.query(comm)
print(boat_name)
comm1 = 'SELECT DISTINCT j.ime, r.dan FROM Jadralec j LEFT JOIN Rezervacija r USING(jid)' \
'WHERE r.dan NOT NULL'
comm2 = 'SELECT DISTINCT j.ime, r.dan FROM Jadralec j LEFT JOIN Rezervacija r USING(jid)'
reservations1 = db.query(comm1)
reservations2 = db.query(comm2)
print(reservations1)
print(reservations2)