Mysql – SUM values in a column but show all the rows after group by
I have the below Table NAME VAL ID SIG DOE 4000 1 0 DOE 5000 8 0 JON 8000 9 1 JON 5000 9 0 DOE 1000 4 0 I need to group by columns NAME and SIG and create…
I have the below Table NAME VAL ID SIG DOE 4000 1 0 DOE 5000 8 0 JON 8000 9 1 JON 5000 9 0 DOE 1000 4 0 I need to group by columns NAME and SIG and create…
Employee: | id | name | department | managerId | +-----+-------+------------+-----------+ | 101 | John | A | null | | 102 | Dan | A | 101 | | 103 | James | A | 101 | | 104…
I'm trying out a few new things right now, and I wanted to create a small Spring/mySQL application. I've set up a docker-compose file as the following: version: '3.3' services: docker-mysql: container_name: docker-mysql image: mysql:5.7 restart: always environment: - MYSQL_ROOT_PASSWORD=root…
I have two tables, table 2 has one row per variable, while table 1 has many rows per variable. I want to randomly select 1000 rows from table 2 (1000 variables) and then join those to table 1. Final table…
This problem I am trying to solve on HackerRank. In this problem, I have to group consecutive dates. Two dates are consecutive when the difference between two dates is 1 and in this problem statement, the start date and end…
As part of our introduction to computer security course, we have a short unit on SQL injections. One of the homework assignments is a basic unsanitized login page. The expected solution is something along the lines of the classic '…
There is a table storing name, speed and timestamp of cars. Each car sends its speed at irregular time intervals, some send more often, some may have not sent their data for a couple of hours, simplified example (real table…
I have a problem with date comparing logic in MySQL and PHP: date difference functions return different results for the same dates. Example: SQL SELECT DATEDIFF('2024-06-02', '2024-05-03 12:57') 30 PHP $x = date_diff( new DateTime( '2024-06-02' ), new DateTime( '2024-05-03…
I am having an sql view "data", which looks like the following: CALMONTH COSTCENTER Kontonummer FIELDNM003 202212 Alpha 123 10 202301 Alpha 123 20 202210 Alpha 223 50 202307 Beta 123 10 I want to keep only the combinations of…
I have the below table: s.userid c.userid c.action 3 3 timeout 3 3 timeout 7 7 confirmed 7 7 confirmed 7 7 confirmed 2 2 timeout 2 2 confirmed For a given s.user_id, I am trying to calculate count(confirmed)/ (count(confirmed)…