Skip to content

Tag: sql

SQL output in one row

For example, I “select * from posts where id = 2” It will output all of the “id 2” information in 1 row After normalization, it have a new table for many to many relation. but I want to know that how can I output the result such as before normalization? Or I need to modify the output i…

Generate a range of records depending on from-to dates

I have a table of records like this: Item From To A 2018-01-03 2018-03-16 B 2021-05-25 2021-11-10 The output of select should look like: Item Month Year A 01 2018 A 02 2018 A 03 2018 B 05 2021 B 06 2021 B 07 2021 B 08 2021 Also the range should not exceed the current month. In example above

Find min and max data column in Table

I have a table that specifies exactly what date and time each employee was in a particular office. EmployeeTable looks like this: id EmployeeID DateP TimeP 1 11111 1397/01/02 01:30 2 11111 1398/05/09 05:30 3 11111 1398/06/07 05:10 4 22222 1398/08/09 06:12 5 22222 1399/02/01 07:15 6 11111 1399/07/02 08:51 7 11…

SQL Substring Case Condition

I’m trying to solve the following question on SQLPAD. Write a query to return the number of actors whose first name starts with ‘A’, ‘B’, ‘C’, or others. The order of your results doesn’t matter. You need to return 2 columns: The first column is the group of act…

Select clause result as comparison expression

In Sql queries can I use the result of a select clause using aggregate functions as an expression for a comparison? For example: Answer Yes, you can do this. You just need parentheses as you would with any subquery: Note that count(b) is not necessary when you know that b is not NULL. There is no need to chec…