如何将其转换为 SQLObject:SELECT DISTINCT columnname WHERE

发布于 2024-10-01 05:39:02 字数 522 浏览 4 评论 0原文

我一直在浏览 sqlobject 和 sqlbuilder 文档和论坛,但我似乎无法掌握那里的信息。

我有一个需要的特定 SQL 查询:

select distinct author from blogtable where keyword = "dust";

多个作者可以发布多个主题。

如果我使用原始 SQL 查询,该查询将在 MySQL 数据库上运行。但我似乎不明白我必须做什么才能使其在 SQLObject 中正常工作。

我看到大量对 sqlbuilder 的引用,但手册页不是很广泛。谷歌小组中提供的示例也好像 SQLbuilder 就是答案一样,但同样,没有我可以理解的具体示例(针对我的问题)。

有人精通 SQLObject 可以向我解释如何在 SQLObject 中实现上述 SQL 吗? 如果不可能,我可以通过 SQLObject 以任何方式将原始 sql 传递到底层数据库吗?

I've been going through the sqlobject and sqlbuilder documentation and forums and I cannot seem to grasp the information there.

I have a specific SQL query that I need:

select distinct author from blogtable where keyword = "dust";

Multiple authors can post about multiple subjects.

The query works on the MySQL database if I use the raw sql query. But I can't seem to understand what I must do to get this correctly working in SQLObject.

I see heaps of references to sqlbuilder, but the manual page is not very extensive. The examples provided in the google groups also talk as if SQLbuilder is the answer, but again, no specific example (for my problem) that I can understand.

Could someone well versed in SQLObject explain to me how I implement the above SQL in SQLObject ?
If not possible, can I pass the raw sql in any way via SQLObject to the underlying db ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2024-10-08 05:39:02

我对 SQLObject 没有太多经验,但从 docs 我推断它应该是这样的:

class Blog(SQLObject):
    class sqlmeta:
        table = 'blogtable'

    author = StringCol()
    keyword = StringCol()

Blog.select(Blog.q.keyword=='dust', distinct=True)

版本2

select = Select(
    [Blog.q.author],
    Blog.q.keyword=='dust',
    distinct=True,
)

sql = connection.sqlrepr(select)

for author in connection.queryAll(sql):
    print author

I don't have much experience with SQLObject, but from the docs I deduce that it should be something like this:

class Blog(SQLObject):
    class sqlmeta:
        table = 'blogtable'

    author = StringCol()
    keyword = StringCol()

Blog.select(Blog.q.keyword=='dust', distinct=True)

Version 2

select = Select(
    [Blog.q.author],
    Blog.q.keyword=='dust',
    distinct=True,
)

sql = connection.sqlrepr(select)

for author in connection.queryAll(sql):
    print author
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文