0

Am sorry if this question sounds so dumb, please help.

I currently use the below MS SQL query to get the list of volunteers on each date and it works perfectly fine,

select Date, count(id) as co from volunter Group BY Date Order by Date

and the result set looks like this

----------
Date       | co
25/2/2016    8
5/3/2016     18
25/3/2016    28

i Now want to perform the same but from a particular date, say from 5/3/2016 to the latest date in the table or say till the last record in the table, how do i do this ? Thank you so much for your time

closed as off-topic by ypercubeᵀᴹ, Balazs Papp, Andriy M, Tom V, mustaccio Apr 7 '16 at 12:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – ypercubeᵀᴹ, Balazs Papp, Andriy M, Tom V, mustaccio
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Add a WHERE clause, like: where Date >= '2016-03-05' in the statement. Also, always tag a question with the appropriate DBMS tag (SQL Server, MySQL, Postgres, Oracle, DB2, etc...) – ypercubeᵀᴹ Apr 7 '16 at 8:25
  • Hi @ypercubeᵀᴹ thank you for reply, it gives me syntax error . "where Date >= 3/19/2016 select Date, count(id) as co from volunter Group BY Date Order by Date" – santhoshkumar B Apr 7 '16 at 8:30
  • 1
    You've missed the quotation marks around the date in @ypercubeᵀᴹ's example. And the WHERE clause goes after the FROM clause. Please read the basics first. – Andriy M Apr 7 '16 at 8:31
  • And really use a sane format for dates. You can't have both '25/2/2016' and '3/19/2016' as dates. In any calendar I know, in Earth, Venus or Mars. Not sure about Neptune, they may have 19 months there. – ypercubeᵀᴹ Apr 7 '16 at 8:35
  • @AndriyM amazing, silly me, this worked like charm, thank you so much – santhoshkumar B Apr 7 '16 at 8:35
1

You just need to add a WHERE clause in the statement, like: where Date >= '2016-03-05':

select v.Date, count(v.id) as co 
from volunter as v
where v.Date >= '2016-03-05'
group by v.Date 
order by v.Date ;
  • Details may differ depending on the DBMS you use. For SQL Server for example, the safe format for the date and datetime types is 'YYYYMMDD', so it would be better to write the where as where v.Date >= '20160305'. In Oracle and Postgres you could use where v.Date >= DATE '2016-03-05'.

  • Date is a reserved keyword in some DBMS, so it would be better to choose another name for that column. Or always prefix it with the table name/alias.

Not the answer you're looking for? Browse other questions tagged or ask your own question.