问题
I'm using asp code i.e classic ASP and SQL server 2000 in this process to display records from database into a table. I have two links called week-wise and month-wise . when the user clicks on this link he will see the data week-wise or month-wise assuming the database have a date field which stores all the dates, when the record is inserted.
So far i'm able to display records present in the table for that particular user. How can i display his/her records WEEK or MONTH wise.
this is the query that I have use
<%
sql="select SUM(grand_total) as total from order_details where emp_number='"&request.QueryString("no")&"'"
rs.open sql,con,1,2
do while not rs.eof
rs.movenext
loop
rs.close
%>
this particular query displays records of that particular result...
回答1:
select
emp_number,
datepart(year, order_date),
datepart(month, order_date),
datepart(wk, order_date),
sum(grand_total)
from order_details
group by
emp_number,
datepart(year, order_date),
datepart(month, order_date),
datepart(wk, order_date)
order by 1, 2, 3, 4
And I'd consider using Prepared Statements to prevent SQL injection.
来源:https://stackoverflow.com/questions/10633618/classic-asp-display-records-from-databse-in-the-table-week-wise-or-month-wise