I’m storing punch-in and punch-out data in a table that looks like so: id empid punchtime 74 4 2021-08-04 17:11:54 171 4 2021-08-06 13:47:45 202 4 2021-08-09 10:14:01 271 4 2021-08-09 18:20:01 308 4 2021-08-10 11:14:54 343 4 2021-08-10 14:46:21 349 4 2021-08-10 15:22:10 380 4 2021-08-10 18:10:58 406 4 2…
Tag: mysql
Order by 2 columns with case
I have a query that searches for user in 2 colums firstUser and secondUser and orders them by first and last name: But this first orders the cases when user is at first user then it orders the case when user is secondUser. Is ther a way to order the whole data by first name and last name no matter
Need help finding syntax error in SQL code [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 9 months ago. Improve this question I have been trying to follow along with a SQL tutorial on YT. Every …
MySQL: Error 1045 – how to set correct rules?
I have MySQL db and need to create a new database. However, I can not do it since I keep getting the 1045 Error. shows following: I don’t even have enough rights for rewoking and granting or creating a new user. Could you please help me what to do? Answer You only have privileges on a schema named db. Y…
MySQL Difficult Where Clause
I need help with a difficult query which I may not explain well with words. The query needs to only return results where all the characters in the code column are in the where clause. Say I had the following table and wanted to return the code and position where ABC. Table: code position ABC 100 ABCD 200 ABCD…
Getting an error using EXISTS operator but correct result with IN operator in
I am getting an error An expression of non-Boolean type specified in a context where a condition is expected while using EXISTS But when I am using IN operator it is giving the correct result. Below is enter image description hereboth query Answer EXISTS is a unary operator, not a binary operator, and takes o…
Show one table that is linked by value to another
I am new to SQL and some points are difficult for me to understand. I have 2 tables: Departments Lectors Departments.head_of_department refers to Lectors.id I need to display lector who is head of department in Department with name X. If it’s possible to select ALL table Lectors and ONLY table Lectors w…
cte FULL OUTER JOIN MYSQL
I have this table(called trial): ‘year1’ refers to values in Column ‘val1’, ‘year2’ to values in Column ‘val2’. I want to get totals of all values grouped by year. So I would like to see a result like: I set up a common table expression(cte) using a self join to…
Lead window function in mysql to find sales
Given this table. I would like to know for each day how many different customers made a sale on date t and and t+1. The result for date 2021-06-30 is 2 because customer 1 and 3 made a sale in t and t+1. Answer Use LEAD() window function for each distinct combination of date and customer to create a flag
How do I do nested if statements in SQL?
Write a program that will check the answers for the latest test. The program will be given a table answers with the following columns: id – the unique ID of the question; correct_answer – the correct answer to the question, given as a string; given_answer – the answer given to the question, …