Sql按日周月数据查询
来源:互联网 发布:苏联集体农庄 知乎 编辑:程序博客网 时间:2024/05/16 12:42
查询本日的记录
select count(*) from tableName where (DATEDIFF(dd, theDate, GETDATE()) = 0)
查询本周的记录
select count(*) from tableName where (DATEDIFF(wk, theDate, GETDATE()) = 0)
查询本月的记录
select count(*) from tableName where (DATEDIFF(mm, theDate, GETDATE()) = 0)
查询本季的记录
select count(*) from tableName where (DATEDIFF(qq, theDate, GETDATE()) = 0)
查询本年的记录
select count(*) from tableName where (DATEDIFF(yy, theDate, GETDATE()) = 0)
///2个参数:
intTop 取多少条
type 是取日,周或月
create PROCEDURE [dbo].[Product_Ranking]
@intTop int,
@type int
AS
declare @sql varchar(500),
@where varchar(70)
if @type=1
set @where=' WHERE (DATEDIFF(dd, ClickDate, GETDATE()) = 0) '
else
begin
if @type=2
set @where=' WHERE (DATEDIFF(wk, ClickDate, GETDATE()) = 0)'
else
begin
if @type=3
set @where=' WHERE (DATEDIFF(mm, ClickDate, GETDATE()) = 0) '
else
set @where=' where 1=2 '
end
end
set @sql='SELECT ProductID,ProductName,
(case StandPrice when 0 then
(case AuctionStartPrice when 0 then
(case CurrentPrice when 0 then 0 else CurrentPrice end)
else AuctionStartPrice end)
else StandPrice end) as Prices
FROM HLShop_Product WHERE
((StandPrice<>0 or AuctionStartPrice<>0 or CurrentPrice<>0) and ProductID IN('
set @sql=@sql+'SELECT TOP '+cast(@intTop as varchar)+' ProductID FROM HLShop_Product_Click'
set @sql=@sql+@where+' GROUP BY ProductID ORDER BY COUNT(ClickID) DESC))'
exec(@sql)
这是一个动态sql的存储过程,功能是对商品进行按日,周,月来进行排行
- Sql按日周月数据查询
- SQL 按日月年统计分析数据
- SQL按日、周、月、年统计
- oracle sql 按日,周,月,年统计
- sql 按日期分组查询
- SQL按日期来查询
- SQLserver 按日、周、月统计数据
- Oracle sql按年、月、周等,分组查询数据
- 按日期查询数量的SQL
- 使用Sql按日期条件查询
- 使用Sql按日期条件查询
- PL/SQL 按日期查询问题
- SQL SERVER查询一个月的数据
- sql语句,查询前一个月数据。
- mysql 按日、周、月、年统计sql语句整理,实现报表统计可视化
- mysql 按日、周、月、年统计sql语句整理,实现报表统计可视化
- sqlserver 按日、周、月统计方法
- mysql按日、月、周、季度分组
- C#.NET 中的类型转换
- Linux 下使用 Audacious 播放 APE 音频
- 请问一下,如何修改重做日志文件的大小?
- 哈利波特》作者在哈佛大学毕业典礼上的演讲
- POJ 3692 最大团
- Sql按日周月数据查询
- 第一篇
- CSDN博客里面挂广告的推荐方法
- ComponentArt Web.UI 2008.1 for ASP.NET
- 原来可以这样插入代码,以前没发现。。。
- ComponentArt Charting 2008.1 for .NET
- asp.net中的缓存
- 真的不明白
- 逆波兰表达式