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 8975653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:56:03+00:00 2026-06-15T18:56:03+00:00

Newbie PL/SQL question: In order to calculate predicted values for a multivariate linear regression

  • 0

Newbie PL/SQL question:

In order to calculate predicted values for a multivariate linear regression analysis, I’d like to multiply each of the regression parameters in Table A by the corresponding variable value for all of the records in Table B, then sum the products for each record in Table B.

Table A contains a single row of parameter values (numerical constants) with n columns, one for each parameter, while Table B contains 100,000+ records which include n columns for each regression variable.

Is there an efficient way to perform these calculations? The simplest approach would be to join the columns in Table A to Table B, which would result in a joined table with n columns containing duplicate parameter values for all 100,000+ records. However, this seems wasteful of processing time and memory.

Or is there a way to declare global constants from the parameter values in Table A (like macro variables in SAS) and then perform the calculations in Table B using the global constant values?

Any help is much appreciated!

Thanks, Robert

  • 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-15T18:56:04+00:00Added an answer on June 15, 2026 at 6:56 pm

    In SQL, one way to do this is with a join and aggregation:

    select t.id,
           max(t.A)*max(case when p.col = 'A' then p.coefficient end),
           max(t.B)*max(case when p.col = 'B' then p.coefficient end),
           . . .
    from data t cross join
         parameters p
    group by t.id
    

    You can also do it with an inline query in the select statement:

    select t.A*(select max(coefficient) from parameters where col = 'A'),
           . . .
    from data t
    

    Assuming that you don’t have too much data (that you have thousands, not millions of rows), either approach should perform reasonably.

    By the way, if the parameters were stored in a single row, then a simple join and multiplication would suffice.

    There is another approach, similar to the first, but perhaps clearer:

    select t.id,
           t.A*p.Acoefficient,
           t.B*p.Bcoefficient,
           . . .
    from data t cross join
         (select max(case when p.col = 'A' then coefficient end) as Acoefficient,
                 max(case when p.col = 'B' then coefficient end) as Bcoefficient,
                 ...
          parameters p
         ) p
    

    I’m adding this, because this is probably how I would really code the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry about the question I am a newbie to sql. i am attempting to
At first - Im sql newbie, sorry for this (mbe typicall) question. I Have
i'm a pl/sql newbie. now i have a question about oracle type . i
newbie question here: I have FreeTDS working and querying a Microsoft SQL server 2008
I'm a newbie in the realm of SQL still, so I have a question
Newbie SQL Query question: I'm using Oracle SQL Developer. I have a table: <name>
I'm a newbie to SQL and .Net and this question might be stupid too
I am a newbie to SQL server. keeping this question as reference.My doubt is
Newbie SQL question here --> I've got an Occurrences table that contains a row
Extreme newbie question. I have my database (SQL Server) set up to cascade deletes

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.