I am trying to insert data into my target table from my source table where in the target table I have an additional column called SaleTo. SaleTo = the SaleFrom based on the MAX SaleSequence. Example of the source table: SaleNo SaleFrom SaleSequence 1 Alabama 2 1 Minnesota 1 1 Virginia 3 Example of target tabl…
SQL insert multiple values and parent id by selecting from same table
How do I insert multiple values and parent id by selecting from same table I tried below and getting an error MySQL said: Documentation #1093 – Table ‘ctg_tbl’ is specified twice, both as a target for ‘INSERT’ and as a separate source for data Answer Your query can be made to wor…
Issues creating a function
Thank you for reading my post and trying to assist. I am pretty new with PostgreSQL and am struggling with trying to create a Function to transform a table column that is currently integer (1,0) into ‘Yes’ or ‘No” and redisplaying the table after the change, what’s your recommend…
What part of my query is invalid with MySQL 5.7?
I have created the following query: It works during development but after testing it on the production server (which is uses MySQL 5.7) I get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘cte1 A…
Parameter returning not in the correct format
I have an async task method that queries a database table for the total amount of Credits in a specific column. I have a string parameter in the method that I use for the query to identify which user is logged in, which is stored in Properties.Settings.Default.Student_Number;. The column for the student numbe…
Bigquery error when powering negative number with decimal(float64)
I’m trying to calculate the CAGR using the formula in BigQuery When running the query, somewhere in middle the values become POW(-0.0310044, 0.333333) and I’m getting error I tried calculating the same value in a calculator and I get the result. What could be the problem and how do I solve it? Ans…
SQL DELETE – Only keep last n records in group (delete old records in group)
[Edit] : this answer helped DELETE FROM Table WHERE ‘RANK’ > 1 I have a table which keeps track of some entity’s status history (tb_status) DDL here is an example status_id ref_entity_aa ref_entity_ab status 1 “a” 1 OK 1 “a” 2 OK 1 “b” 1 OK 1 “b&#…
Implement database schema for organizing historical stock data
I am new to MySQL, I try to use MySQL to store my stock data. I followed the answer by boe100 in reference: Database schema for organizing historical stock data I create my table as follows: mysql> describe StockDailyQuotations; Field Type Null Key Default Extra ts_code varchar(9) NO PRI NULL trade_date in…
SQL Query Subtracting Values from Two Tables
I have two tables, demand and fte, that have department, shift and demand or fte. I need to calculate the need (demand – fte). What I get is a table with 9 entries. I’ve run into this before and for …
how to use first_value with reset
WITH t AS ( SELECT * FROM (VALUES (‘2021-10-09 23:58:34.000’, ‘2021-10-10 00:00:00.000’, ‘task_completed’, ‘00001’), (‘2021-10-10 00:00:01.000’, ‘2021-10-10 00:…