求一句SQL语句,详情请进

zcxverygood123456 2007-05-17 05:56:02
求一句SQL语句
------------------
归档
2007年05月(4)
2007年04月(9)
2007年03月(14)
2007年02月(17)
2007年01月(18)
--------------------------
在博客里有这个归档,SQL语句怎么实现???
============================================
我的数据表为:
二、博客文章bk_wz
w_id
w_name 文章名称
w_nr 文章内容
w_time 发布时间
...全文
663 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcxverygood123456 2007-05-18
  • 打赏
  • 举报
回复
可以了
非常谢谢
接分了
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
哎,前段时间在学管理,把技术放一边了。
我该充电了
向高手学习
jinjazz 2007-05-17
  • 打赏
  • 举报
回复
where convert(varchar(6),w_time,112)= '"+Request.QueryString["t_time"].ToString().Replace("年","").Replace("月","")+
fcuandy 2007-05-17
  • 打赏
  • 举报
回复
c#中的字串的replace方法你不会用?
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
(....把年替换成-,把月替换掉)
---------------------
这个地方怎么写啊?

fcuandy 2007-05-17
  • 打赏
  • 举报
回复
select * from bk_wz where convert(varchar(7),w_time,120)= '"+Request.QueryString["t_time"].ToString().Replace(....把年替换成-,把月替换掉)+ "' ORDER BY w_time
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
恩,可以了
非常感谢fcuandy
--------------------------------
还有个问题,
Request.QueryString["w_time"]
传的参数是w_time=2007年05月
怎么在显示列表读出来呢?
即SQL语句怎么写啊?
select * from bk_wz where w_time= '"+Request.QueryString["t_time"]+ "' ORDER BY w_time DESC";
fcuandy 2007-05-17
  • 打赏
  • 举报
回复
打多了个SELECT。把最后面的SELECT去掉
fcuandy 2007-05-17
  • 打赏
  • 举报
回复
string strSel1 = "select replace(convert(varchar(7),w_time,120),'-','年') + '月' w_time,count(*) num from bk_wz group by select replace(convert(varchar(7),w_time,120),'-','年') + '月' ";
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
string strSel1 = "select replace(convert(varchar(7),w_time,120),'-','年') + '月' w_time,count(*) num from bk_wz group by convert(varchar(7),w_time,120)";
-----------------------------------------------------
用上面这个语句,出现以下出错:
--------------------------------------------
列 'bk_wz.w_time' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
<asp:datagrid id="DataGrid2" runat="server" GridLines="None" CellPadding="0" AutoGenerateColumns="False"
ShowHeader="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.w_time","{0:Y}") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
-------------------------------------
SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]);
string strSel1 = "select convert(varchar(7),w_time,120) from bk_wz group by convert(varchar(7),w_time,120) order by convert(varchar(7),w_time,120)";
DataSet MyDataSet = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter(strSel1,MyConnection);
myCommand.Fill(MyDataSet,"999");
this.DataGrid2.DataSource = MyDataSet;
this.DataGrid2.DataBind();
=============================================
代码如上,还是出现上面的错,请教错在哪儿?
fcuandy 2007-05-17
  • 打赏
  • 举报
回复
很明显你自己绑定时列名的问题.
简单,给列个别名就可以了

select replace(convert(varchar(7),w_time,120),'-','年') + '月' w_time,count(*) num
from bk_wz
group by convert(varchar(7),w_time,120)
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
select convert(varchar(7),w_time,120),count(*) from bk_wz group by convert(varchar(7),w_time,120) order by convert(varchar(7),w_time,120)
======================================
使用这个语句,就出现上面的错误。
w_time 这个字段是有的
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
DataBinder.Eval:“System.Data.DataRowView”不包含名称为 w_time 的属性。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: DataBinder.Eval:“System.Data.DataRowView”不包含名称为 w_time 的属性。

zengxiongbin 2007-05-17
  • 打赏
  • 举报
回复
select convert(varchar(7),w_time,120),count(*) from bk_wz group by convert(varchar(7),w_time,120) order by convert(varchar(7),w_time,120)
fcuandy 2007-05-17
  • 打赏
  • 举报
回复
select replace(convert(varchar(7),w_time,120),'-','年') + '月',count(*) num
from bk_wz
group by convert(varchar(7),w_time,120)
wuxing2006 2007-05-17
  • 打赏
  • 举报
回复
select sum(id) from news group by date
zcxverygood123456 2007-05-17
  • 打赏
  • 举报
回复
回oldmoon(电子商务人,电子商务路) :
---------------
二、博客文章bk_wz
1、w_id ----------文章ID
2、w_name ----------文章名称
3、w_nr ------------文章内容
4、w_time ----------发布时间
===============================
回yiyioo(天一(一个人的Team)) :
怎么提取啊?
zengxiongbin 2007-05-17
  • 打赏
  • 举报
回复
select convert(varchar(10),w_time,120),count(*) from bk_wz group by convert(varchar(10),w_time,120) order by convert(varchar(10),w_time,120)
yiyioo 2007-05-17
  • 打赏
  • 举报
回复
select 年月,count(年月) from table group by 年月 order by 年月 desc

年月需要从发布时间里提取
加载更多回复(1)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧