當前位置: 首頁>>代碼示例>>Python>>正文


Python Db.query方法代碼示例

本文整理匯總了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"
開發者ID:dujodujo,項目名稱:orangutan,代碼行數:33,代碼來源:Xjadralci.py

示例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.")
開發者ID:dujodujo,項目名稱:orangutan,代碼行數:33,代碼來源:Rating.py

示例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)
開發者ID:dujodujo,項目名稱:orangutan,代碼行數:33,代碼來源:Jadralci.py


注:本文中的Db.Db.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。