I have a table as below: ItemName 1mth_presale_cost 2mth_presale_cost 1mth_postsale_cost 2mth_postsale_cost 1000 10.1 12.1 12.5 15.1 1001 20.2 15.2 25.2 17.3 I want the result to be like below table: ItemName 1mth_cost 2mth_cost 1000 10.1 12.1 1000 12.5 15.1 1001 20.2 15.2 1001 25.2 17.3 I don’t want to use UNION for this. Answer First each row converted into two
MariaDB Created view takes too long
I have a problem. I have a table with 6 million records in it. Every record has a column dateTime, and for my code I need the most recent 16 records in ascending order. This took too long to query directly out of the original table, so I created a view using the following query: This means that the view
SQL MAX(col1, col2) with priorities
I need to select row with MAX(val1) for each group. If there is more than one row with equal val1 = MAX(val1) I need to select from them row with MAX(val2), etc. In pseudo code it should be like this: For example: I have table nums with one TEXT column name and three INTEGER columns — id, num1 and num2
Full text search returning too many irrelevant results and causing poor performance
I’m using the full text search feature from Postgres and for the most part it works fine. I have a column in my database table called documentFts that is basically the ts_vector version of the body field, which is a text column, and that’s indexed with GIN index. Here’s my query: The dictionary is english_unaccent because I created one based
Calculate total units sold and total sales value
Can you help me check my answers whether is this the right way? Im really new to database This is the question This is my answer The reason i use with read only constraint was to enhance the security! Answer The way I see it, query would look like this: If compared to yours: don’t select columns you don’t need
Conditional debit from credits and running balance using SQL
I’ve data like below in a table cryptotransactionledger id transaction_typeid transaction_type amount totalcoins 1 1 bitcoin-credit 30 30 2 2 ethereum-credit 20 50 If I spend bitcoin, I’m putting a new entry like below in the same table with transaction_typeid 3 and similarly for ethereum with transaction_typeid 4 id transaction_typeid transaction_type amount totalcoins 1 1 bitcoin-credit 30 30 2 2
Rank Date based on today’s date
I have a simple date dimension, I’m attempting to write a Window function (without much luck..) to net the following result. where 1 is today and 0 is yesterday. What can I try next? I’m unsure what to search for. Answer Assuming the dates are continuous, we don’t even need analytic functions but instead we can just use DATEDIFF: Demo
Got an error while executing query {“statusCode”:500,”error”:”Internal Server Error”,”message”:”syntax error at or near “)””}
I have a db with a primary key address I want to write a request that would delete rows that match the address that I pass in the array. I have this in my missing-urls.js file and use this query in my query/missing-urls.js file When I run this request I got an error. What I am doing wrong? Answer You
Query condition where a value is in a comma separated string
I have a table in which one of the table columns third_row stores a comma-separated list of numbers as a string but when its value is A then it means a combination of all the possible numbers. How do I approach this so that the query returns all the rows that have the third_row as A and the rest where
How to insert to a table if there exist a value in another table
i have tried this I want to insert to examqst only if there is a row examid in examname table and s_id in examname have a perticilar value Answer You could an INSERT INTO…SELECT: