SQL query for date change for upcoming events [closed] - mysql

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.

Related

How to write query to retrieve latest time value closest to today in SQL? [closed]

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 1 year ago.
Improve this question
How to retrieve latest value for each card from time from the table in SQL including sensor id and event type closest to todays date please?
create table events (
sensor_id integer not null,
event_type integer not null,
value integer not null,
time timestamp unique not null
);
I have tried code below
SELECT TOP 1 *
FROM events
WHERE events.time < "2021-01-01 00:00:01"
ORDER BY events.time DESC
Top 1 does not work in mysql and limit 1 did not get me the results.
I need to get latest time value for each sensor_id not only the latest value for the whole table.
You can use order by and limit. Let me assume that you mean on or before today:
select e.*
from events e
where e.timestamp <= now()
order by e.timestamp desc
limit 1;
If you want future dates as well, this can be tweaked.

SQL query. Should I loop through specific date range? [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 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

Between And Greater Than Date Should Be Implement In Same Query [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 2 years ago.
Improve this question
I have two DateTime columns like start_datetime and end_datetime. these fields contain DateTime value.
Here itself I need three different outputs. while you search, "15-09-2020 00:00:00" to "26-09-2020 23:59:59" it will display the first two lines. if you search like "26-09-2020 00:00:00" to "13-10-2020 23:59:59", it should result in three rows.
Instead of if you search, "10-09-2020 00:00:00" to "18-09-2020 23:59:59", it will show the first two rows.
In this case, I am stuck at the query. if I am using between some results won't come. if I am using greater than a symbol, some results won't come.
store the date time format in YYYY-MM-DD H:I:S, so you can easily
SELECT *
FROM table_name
WHERE start_datetime BETWEEN value1 AND value2 AND end_datetime BETWEEN value1 AND value2;

Selecting oldest data first [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 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

Mysql find names not in previous dates [closed]

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'
);