日期:2014-05-18  浏览次数:20608 次

sql 语句改错。。。
select count(tm.ID) from dbo.T_Money as tm  
left join dbo.T_Item as ti on tm.ID =ti.ID
where ti.item ='AAA' and tm.[datetime] between '2012-03-01' and '2012-03-21') order by tm.ID DESC 

我想查的是两个时间之间的 数据 还有个条件就是 ti.item ='AAA' ,写出来就是查询不对,求高手,。。坐等,,晚上也登。。
最后等到的是查询出来的总条数。。。

------解决方案--------------------
SQL code

select count(*) from dbo.T_Money as tm   
  left join dbo.T_Item as ti 
    on tm.ID =ti.ID
      where ti.item ='AAA' and tm.[datetime] between '2012-03-01' and '2012-03-21'
        order by tm.ID DESC

------解决方案--------------------

SQL code

select count(*) from dbo.T_Money as tm   
  left join dbo.T_Item as ti 
    on tm.ID =ti.ID
      where ti.item ='AAA' and tm.[datetime] between '2012-3-01' and '2012-3-21'
        order by tm.ID DESC

------解决方案--------------------
SQL code

select count(*) from dbo.T_Money as tm   
  left join dbo.T_Item as ti 
    on tm.ID =ti.ID
      where ti.item ='AAA' and(tm.[datetime] between '2012-3-01' and '2012-3-21')
        order by tm.ID DESC

------解决方案--------------------
你这个count 就会返回一个值 无需加order by



SQL code
select count(tm.ID) from dbo.T_Money as tm   
left join dbo.T_Item as ti on tm.ID =ti.ID
where ti.item ='AAA' 
and tm.[datetime] between '2012-03-01' and '2012-03-21'

------解决方案--------------------
把你的left join 改成inner join 试试看
------解决方案--------------------
一个是ORDER BY的对象不在查询对象中吧