I have two databases (A and B). I need to find the percentage between number of **rows in A** and number of **rows in B** (for example, if I have *100 rows in A* and *10 in B*, *result will be 10%*). Is there a way to do so using **JOIN** operator? I tried with “**SELECT COUNT(*) FROM DBA**” to
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 …
How can I find the max “income” from every “product” in every “province”? [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 I have this table PRODUCT PROVINCE INCOME Apple Seville 13.2 Melon Almeria 3.6 … ……
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…
Optimizing MySQL-Query for removing duplicates and adjusting foreign key references
i have following tables:address_table and customer_address_table The address table stores addresses and the customer_address table stores the relation between customer and address. A customer can have multiple addresses, therefore the second table. In the address table there are duplicate rows (different id b…
select the data of all the students scoring highest marks in each subject group by city
I am using mysql version 8.0.23 the given table is:- and I want to get the complete data of the students having highest marks in each subject from each city — I had used this but still I am not able to see name and id of that student Answer here is one way using window functions: