Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:20:07+00:00 2026-06-08T08:20:07+00:00

hey all i am stumped by this query and have thought it over and

  • 0

hey all i am stumped by this query and have thought it over and cant seem to put my head on it.

i have three tables, account, suppliers and scores

an account has many suppliers and a supplier has many scores.

what i would like to do is display all the scores that have been changed or created within a two week period that pertain to an account. i dont want to pull the whole db as it has over 2 million lines of code so i want to leave the calculations to be preformed by sql.

the trouble is making a clear sql statement.

this is my thinking.

sql=""
scores = ActiveRecord::Base.connection.execute(sql)
@scorecards = []
@scorecards {|sc| sc << scores}

this way i can save all my results in a array and ill be able to work with them from there.

my sql statement looks like this:

SELECT * FROM sms_development.scores WHERE DATE(created_at) = CURDATE() - INTERVAL 14 DAY AND CURDATE() OR DATE(updated_at) = CURDATE() - INTERVAL 14 DAY AND CURDATE();

now here is where i am confussed i have to run this statement for each scorecard, then match it to the score_id in the suppliers table and then match the suppliers id to the the suppliers_id in the accounts table.

what is the best way of accomplishing this within the SQL query?? sorry if its a simple question i am new to MySQL. and this seems like it could get hairy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:20:08+00:00Added an answer on June 8, 2026 at 8:20 am

    I would let rails handle this for you.

    Add a has_many :scores, :through => :suppliers to your account model, and belongs_to :account to your scores model, then load scores using:

    Scores = @account.scores.where("created_at > ? Or updated_at > ?", 2.weeks.ago, 2.weeks.ago)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all- I have looked this up on here and Google but none of
Hey all, this is my query string here: SELECT SUM(Total) as Total, AdministratorCode, SUM(WOD.Quantity)
Hey all here are my tables i have placed in a DIV for each.
Hey all. I'll try to make this brief and simple. :) I have 40
Hey all. Ive got a headache trying to get my head around this. I
Hey all i have a mind bug with this wile loop , i am
hey all, Im stumped. I have the following code..works fine in all browsers except
hey all.i'm newbie at this problem.i have this data in table result: item range_code
Hey all, I am not quite getting why this doesn't seem to be working.
Hey all. Here is the scenario. I have the below code, and I'm needing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.