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: mysql
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 …
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 …
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 …
Query returns multiple id’s
I have a query that finds the most frequent numbers in multiple columns (named S1, S2, S3, S4, S5 and S6. The query seems to be working pretty good, but it doesn’t count the total number per id in the …
mysql update with if and max
I have lost hours on this and nothing works for me. I have filed strp_aa that is default NULL. The filed strp_aa should update only if its null with MAX strp_aa + 1, and if its not null if it already has a number it should stay the same. short version of code is Also tired I tried multiple things
Sort a table but keep groups of rows together
How do I sort a table by it’s minimum value per group but at the same time keep a group of rows together. Below a simple example of what i am trying to accomplish. The table is sorted by the lowest group value, but the group remains together. I am pretty sure this question has been asked already but i
Group by not getting the expected results in mysql
I have the next query: That is working perfectly and returning 9 rows: I want to group the results by boat type and get the number of boats per type. However, when I do: I´m getting: but according to the first query, I´m expecting What am I missing? Answer I suspect that you want: That is: move the DISTINCT within