Skip to content

Tag: mysql

Recode column values in MySQL

I am dealing with a column named UCODE130 that has values anywhere from 1-130. I would like to replace the values with ranges. For example, I want to replace any 1, 2, 3, or 4 found in that column with a string “1 – 4” instead. I do not want to do just a select statement – I want to

MySQL how get middle point between two given times

I have 2 times value 06:00:00 and 14:00:00 expected result is 10:00:00 FYI. I want to write this into my trigger Answer You can convert your times to seconds, then find the middle value, and convert back to time The middle value of two numeric values is simply (a + b) / 2

How to union all, but separate the columns in mySQL

The first query returns the data for the last 7 days, and returns 90 in total, while the second query returns data for the previous 7 days, returns 55 in total. Current output is: But the output should be: Answer You can use conditional aggregation:

SQL subtracting 2 subqueries

Fairly new to SQL and I wanted to see if I could get some help with subtraction. I want to subtract studentstaken – studentsnotreviewed and then as assign the alias total to the operation. I was thinking something along the lines of But getting some syntax problems I’m not too sure about. [Sample …

Best practice to keep track of timestamps? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question If have been trying to keep track of multiple timestamps regarding user-related inputs and my …

Select records within 5 kilometers with group by

I have an application that uses coordinates. I want to select records within 5 km that were thrown in the last 5 minutes. How can I do this easiest? I want to write a procedure. The values I will send to the procedure are latitude (float 11,8) and longitude (float 11,8). Example table: I found a query like th…