当前位置: 首页>>代码示例>>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;未经允许,请勿转载。