I am trying to get a sum from my DB with a query written in hibernate @Query(value = “SELECT COALESCE(sum(charge),0) FROM initial_charge I INNER JOIN task T ON T.id = I.task_id ” +” …
Tag: mysql
Select specific number of sub items
I have this collection of data that I made a query on it Hotel_Id | User_Id | Comment | Date 1 1 Hello world 2020-1-1 1 2 Hello world 2020-1-1 1 …
How to improve union query?
I have a query which is ‘working’ but slow and feels very poor and I don’t want to have to update each time we add/remove a supplier! Basically I have a table of ‘prices’ and for each suppler I need …
Using MySQL to calculate difference of 2 columns to equal a 3rd column
Ok so I’m using SQL in phpmyadmin trying to calculate the difference from 2 columns and add that value to a 3rd column. I’ve imported my data by CSV into the database. I’m trying to “autosum” like excel and Access in SQL database. My columns are “Tax Collected” – “Tax Paid” = “Tax Gain” Imported CSV Answer That we could
How to shorten mysql join query to avoid manual typing of each row?
I have a table that gets new rows for eg. I’d add more than 100 features like phone_number, username to the processed_donors to this table very soon.IS it possible to simplify this json_object(****) so It’s not an evergrowing list? Some way to use pandas+python, select * etc? Answer I think you could do this in two steps. First, you need
query with sql max function
table view with 4 records Would the following query work if I wanted to select the 2nd and 3rd records? Answer As your date values are not in well formatted, you need to first convert your values into DATE and then apply other logic. Please check my updated script now- Issues: You value in completion_date column is string. as a
MySQL Filtering Results from a One-to-many Relationship
I have two tables. quotes_table and flags_table. The quotes_table has a one-to-many relationship with the flags_table – each quote can have multiple flags. flags_table.id_flag is a foreign key of …
Sum multiple columns in multiple rows
I have following data structure for sales: I need to know how many products with id=1 were sold for the last 12 month. If we are in June 2020 I need to sum M01, M02, M03, M04, M05 (WHERE year=2020) and M06, M07, M08, M09, M10, M11, M12 (WHERE year=2019) WHERE id=1. I should get a value of 36. Please,
How to fill the custom columns with joined values
I have a query like: I have 2 tables: sales_order_grid (where the main data is) sales_order_status_history (where I want to attach the status data) I need to fetch custom columns values of the latest statuses (I mean there could be more than one status for the order, but the date differs). Could you please help me with that? Answer I
From string, extract a word starting with a keyword (SQL or any other methods?)
Let’s say I have a string of random characters, and I want to extract only the string that starts after a specific keyword (including the keyword). How could I do so using MySQL or MariaDB? ………….. String example: axdsSSFddlwie ====> SSFddlwie aldfklafnlanaSSFiiie ====> SSFiiie iiiSSFnnnn ====> SSFnnnn Thanks for the help! Answer Using the base string functions we can try: