I have two tables, a table called companies_display with information about publicly traded companies such as ticker symbol, market cap etc. and a partitioned table stock_prices with the historical stock prices for each company. I want to calculate the beta of each stock and write that into companies_display. For that I wrote the function calculate_beta(ticker) that calculates it: The function
Tag: loops
Creating a SQL Loop to Change the Table Name
I am needing to change the ending number of the table name in a loop to go from 1 through 12. This is a more straight forward example of my actual problem, but if this can be solved, then I can duplicate the results later on (Actual problem is using the past 12 months on a rolling basis for a
LOOP/FOR statement on oracle script
I’m running an ansible playbook that runs an sqlplus script to an Oracle DB. Basically the script creates a CSV file with some server info. The query is pretty much autogenerated, so it will be difficult change it. The problem is that this query brings all the 5000 server and I need only 200. I want to add a LOOP/FOR
Is there a way to loop through selected columns in plsql
I have a table TestTable with columns of col_test1, col_test2, col_test3 … and I want to create a loop that accesses each of these columns individually and find the max value and place it in the variable made in the declare block and simply dbms.out.put it. The output I get is just the string ‘col_test1’which should be 50. This is
How to use a for loop to insert multiple records in a database table
I have simplified my problem into the following code: $sql_abc = “CREATE TABLE $tbl_abc( x INTEGER(255) ) “; echo “About to execute $sql_abc”; if (mysqli_query($conn, $sql_abc)…
Python – Running a SQL in a loop based on column value
I am trying to build a SQL query that runs based on certain conditions (if a column is filled run Query 1 else Query 2 and so on) as shown below: I am trying to build something like the above but the number of fields as variable (fields like col_a and col_b) are 6 in number. Is there a way
Inserting Multiple of same records into SQL temp table based on value in column
So I have table with the following records: I want to create a script to iteratively look at the Cnt_Repeat column and insert that same record in a temp table X times depending on the value in Cnt_Repeat so it would look like the following table: Answer One method supported by most databases is the use of recursive CTEs. The
Loop through a table valued function
I have a table x which has columns y and z it has 10 rows of data. I then have a table-valued function getDetails(y,z) which takes values stored in table x in columns y and z to return a table tb with three columns. I need to write a tsql query that loops values from table x through function getDetails(y,z)to
Having trouble wrapping my head around how to write a particular loop
I am querying a SQL database to return open work order operations. My query is producing the Work Order number, operation status and due date. I am trying to figure out how to iterate through the array that is returned and: Gather the sum of operations due within a week Gather the sum of operations due in the second week
SQL Query, loop through data
I have a database with the following fields: UserID, DateRecorded and Score. A new entry is added to the table each time the score is updated. Here is an example of a user record: From the query I would like it to show me only the scores of all users with the earliest DateRecorded. Although not much familiar with cursors,