gpt4 book ai didi

MySQL 查询不工作

转载 作者:行者123 更新时间:2023-11-30 23:30:26 25 4
gpt4 key购买 nike

在我的网站上,用户有一个“待办事项”列表。在测验中获得最低水平的成就后,该测验将从用户的待办事项中删除。下面的代码适用于产品,但不适用于通过“BusinessRelationship”列出的任何测验。

def not_quizzed_things
taken_company_ids = quizzes_taken.select{|q| q.thing_type == 'BusinessRelationship'}.map{|q| q.thing_id}.uniq
conds = "business_relationships.from_company_id = ? and (business_relationships.legit_quiz_questions_count + c.legit_quiz_questions_count) > 0"
args = [company_id]
unless taken_company_ids.blank?
conds += " and c.id not in (?)"
args << taken_company_ids
end

quiz_companies = BusinessRelationship.find(:all, :joins => "join companies c on c.id = business_relationships.to_company_id", :conditions => [conds]+args, :order => "id", :limit => 0)
quiz_companies = [company] + quiz_companies unless company.legit_quiz_questions_count <= 0 || quizzes_taken.select{|q| q.thing_type == 'Company'}.map{|q| q.thing}.include?(company)
n = 20 - quiz_companies.size

taken_products_retailer_ids = quizzes_taken.select{|q| q.thing_type == 'ProductsRetailer'}.map{|q| q.thing_id}.uniq
conds = "products_retailers.company_id = ? and (p.legit_quiz_questions_count + products_retailers.legit_quiz_questions_count) > 0"
args = [company_id]
unless taken_products_retailer_ids.blank?
conds += " and products_retailers.id not in (?)"
args << taken_products_retailer_ids
end
quiz_products_retailers = ProductsRetailer.find(:all, :joins => "join products p on p.id = products_retailers.product_id", :conditions => [conds]+args, :order => "id", :limit => n)
quiz_companies + quiz_products_retailers
end

控制台结果:

ruby-1.8.7-p352 :007 > y u.quizzes_taken.last
--- !ruby/object:Quiz
attributes:
thing_id: "213"
created_at: 2012-06-09 20:07:32
end_time: 2012-06-09 20:07:56
current_attempt_id:
thing_type: BusinessRelationship
updated_at: 2012-06-09 20:07:56
order: "2388,2389,2390,2391"
id: "467"
correct_count: "4"
user_id: "392"
attempt_count: "4"
start_time: 2012-06-09 20:07:32
attributes_cache: {}

非常感谢任何想法或建议!

最佳答案

我会查看您的调试窗口以查看发送到数据库的确切 SQL,并查看为什么您的查询未按预期出现。从您的数据库返回到您的代码。

关于MySQL 查询不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10991625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com