so here is the query select * from test order by pow(c1 – 8, 2) + pow(c2 – 5, 2) limit 3 is there any way to show order section -> “pow(c1 – 8, 2) + pow(c2 – 5, 2)” for each record in result ?
Tag: sql
Conditional UPDATE MariaDB (MySQL)
Code: UPDATE COMPANY SET id=’21’ WHERE id=’20’; Error: SQLException: Duplicate entry ’21’ for key ‘PRIMARY’ I want to UPDATE the primary key field in this case it’s called ‘id’ to another value …
SQL – Generate column from sum of columns from different table
I have two tables: The first one contains numeral values, it looks like this: The id column is the primary key; it has the attribute AUTO_INCREMENT. All columns have the datatype INT. Now my …
Query for datediff between rows where value was unchanged, grouped by the value
I am looking to query an invoices table which also keeps track of which “program” customers were on at the time of their purchases (not the best way of storing that but it is what it is and I’m left …
Speed up query on JSONB object field Postgres / indexing a JSONB field
I am trying to speed up queries on an object field in Postgres. The table I am searching has the following structure: page_id: integer lang: varchar(2) images: jsonb The images JSONB field contains …
Postgresql – How to identify latest record of a combination of 2 columns (Example inside)
In PostgreSQL, if i have this kind of record : |——————|———————|——————| | corona_country | corona_patient | corona_suspected | |——————|———̷…
SQL determine if more than one column on a given row has the same value
I have a SQL Server table that includes 9 columns used to indicated what things to include or exclude in part of the UI. Each column can have the value ‘A’, ‘X’, or blank. Each row should have at most 1 ‘A’ in any of the columns. Due to an error many columns have multiple &…
How to create id field with auto increasement while using stored procedure?
I have this stored procedure. How can I select a variable as a field that can +1 value in every row of results of sp? I need it for making a virtual id field. please help me. CREATE DEFINER=`root`@`…
How would I insert the same row with all the different subquery values at the same time, almost like an iteration over the subquery?
CREATE TABLE messages (messageid INTEGER PRIMARY KEY , message VARCHAR(150) , sender VARCHAR(40) , recipient VARCHAR(40)) CREATE …
How to get all items that has added action but wasn’t deleted
I have an Activity table in which user’s activity on actions is stored. There is two type of actions in column type that are required to check: add_favorite remove_favorite So same object can be …