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 2 years ago.
Improve this question
I am making a hotel management system. I need your help with appropriate statement to execute. Can you please have a look?
This is all room_types = 3, their check-in and check-out date
If I make query "SELECT * from rooms WHERE room_type = 3 AND check_in_date BETWEEN '2021-02-12' AND '2021-02-13'" this is what it returns
it returns only one room
but BETWEEN '2021-02-12' AND '2021-02-13'" there will 5 rooms with room_type = 3 in house. How can write a query that returns it?
I need to return these
Because all those 4 rooms with type=3 will be in house BETWEEN '2021-02-12' AND '2021-02-13'
I am using MariaDB with ORACLE syntax.
Thank you!
I suspect that you want a date range overlap:
select *
from rooms
where room_type = 3
and check_in_date <= '2021-02-13'
and check_out_date >= '2021-02-12'
This brings rooms that have a reservation that overlap the given range.
From your first screenshot, I see only one room with a checkin date between the 12th and the 13th. That room is returned in the result in your second screenshot. To my eye that one row is the expected result for the criteria you specified.
Maybe as GMB suggests, you are looking to consider both the checkin date and the checkout date?
Karl
Related
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 2 years ago.
Improve this question
i want to select info which was registered in database earlier first one by one,
its i want to select oldest info first then newer, like to be in order (first come first serve) one by one
like
Today - some info
Yesterday - some info
day before yesterday - some info
SELECT info FROM table ORDER BY A DESC LIMIT 1
table
id info date_registered
1 john 9999-12-31 23:59:59
Your question is vague, but there's various ways you can do it.
What are you doing with this?
check out OFFSET and LIMIT, which you'd do something like run your query and then increase the offset each time you run it.
just use whatever programming language you're using to loop over the result set? IE remove the limit.
3 it multiple times and add a where clause which uses the previous return value.
SELECT info
FROM table
where date_registered < '9999-12-31'
order by date_registered desc
limit 1
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to run a query in sequelize or SQL where select current month data and only show just upcoming date data like some kind of events if that day pass then next event or date will be showing like this I have 3 dates in this month
1 2020-03-15
2 2020-03-22
3 2020-03-27
So before 15 I want to only no 1 date after 15march pass I want only no 2 date and goes on
If you want to show the next date in the future, then it would be something like:
select t.*
from t
where date > current_date
order by date asc
fetch first 1 row only;
The exact syntax might vary by database -- say now() or getdate() instead of current_date; or select top (1) or limit 1 instead of the fetch clause.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
i need to find the the sum of the salary spent in every year in every department - the problem is that i have two columns of date - how can i "extract" the year from this dates?
What you're likely looking for is using the YEAR function to get the start date of the salary and summing up per department.
This is making the assumption that you want to count the full salary based on the year in which the pay started. Additionally, there may be added complexities if for example, someone worked for multiple departments at once. If you are asking which out of from or to date should be used to count which year the salary falls in, this is 100% up to you based on your requirements.
SELECT
a.dept_no as `Department`,
YEAR(b.From_date) as `Year`,
SUM(b.salary) as `Salary`
FROM
dept_emp a
INNER JOIN
salaries b
ON
a.emp_no = b.emp_no
GROUP BY
a.dept_no,
YEAR(b.From_date)
ORDER BY
a.dept_no
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am currently trying to solve a MySQL exercise and I am having issues with finding the right command.
There is a table called 'orders' with the following columns: orderNumber, orderDate, requiredDate, shippedDate, status and customerNumber.
The question says to show the orders payed in the summer (columns to be shown: orderNumber and orderDate).
I think the answer should be something like this, but I can't figure out how to precise the month (probably something with IN or BETWEEN but I can't solve it):
SELECT COUNT(orderDate), orderNumber
FROM orders
GROUP BY orderNumber;
You Use the MONTH function to get the month for the date and compare it with the summer period using BETWEEN
SELECT orderNumber, orderDate
FROM Orders
WHERE MONTH(w) BETWEEN x AND y
AND status = z
w is the date column to use, not sure which one it is
x & y represents start and end month of summer where you live
z the status the order gets when it’s paid
Is not clear how you distinguish between paid and unpaid but, anyway, for select the order, if you want the order list you could use
SELECT orderDate, orderNumber
FROM orders
where orderDate between str_to_date('2018-06-21', '%Y-%m-%d')
and str_to_date('2018-09-21', '%Y-%m-%d')
the aggregationion seems not necessary to me ..
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a Mysql database that contains a list of names and dates of volunteers going back five years. What statement would I use to generate a list of new names after a specific date (i.e. people that have not volunteered in the past).
Here is an example, I have a list of 100 different volunteers who have volunteered many times on different dates over 5 years to the present. Some may have volunteered once, others 5 times, etc. Dave is a new volunteer who volunteered on February 6, 2015. I wish to generate a list of new volunteers after 2014-11-29. This list would pick up Dave's name only in this instance.
Try this:
SELECT name
FROM your_table
WHERE column_date < DATE_SUB(NOW(), INTERVAL 5 YEAR);
Or:
SELECT name
FROM your_table
WHERE column_date < DATE_SUB(CURDATE(), INTERVAL 5 YEAR);
EDIT (after the comments):
Try this:
SELECT DISTINCT aa.name
FROM your_table AS aa
WHERE aa.id NOT IN (
SELECT id
FROM your_table
WHERE column_date < '2014-11-29'
);