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 5 years ago.
Improve this question
I'm trying to solve this problem. But I have difficult working with dates, dates overlapping, whatever.
I would like to get all events that was happening in March, 2007.
My events table:
ID
name
start_date
end_date
I am trying:
SELECT *
FROM events
WHERE (MONTH(start_date)<=3 AND
YEAR(start_date)<=2007) AND (YEAR(end_date)>=2007 AND
MONTH(end_date)>=3)
Can you help me?
Normally, you would use:
where start_date < '2007-04-01' and end_date >= '2007-03-01'
This will give any event active during the month.
If you want events that are only in the month, then:
where start_date >= '2007-03-01' and end_date < '2007-04-01'
Related
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 6 years ago.
Improve this question
Below is my database table.
what will be the sql query to calculate average score of all topic1 entries,of all topic2 entries and so on with where clause(where event_date between this to this)?
use group by
select topic_name, avg(score)
from my_table
where event_date between '2016-03-01' AND '2016-03-31'
group by topic_name
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'
);
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
In my table, there is one filed named "Reporting_Date". And I want to get Weekday name of all dates from table. Weekday like sunday, monday. How does it possible in mysql?
Use DAYNAME(date)
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_dayname
mysql> SELECT DAYNAME('2007-02-03');
-> 'Saturday'
SELECT DAYNAME(Reporting_Date) FROM <table_name> WHERE 1
I guess you could model date format according to your requirements.
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 8 years ago.
Improve this question
I need to show the month with the highest number of quantity sold.
I don't know how to do that. Please help thank you.
I have:
id, prod_name, price, q_sold, month
the q_sold must sum up with the number of month input.
You can order your result by the sum and take only the first entry with limit 1
select `month`, sum(q_sold) as sold_sum
from your_table
group by `month`
order by sold_sum desc
limit 1