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

一个SQL语句,帮我检查一下错误,谢谢!!

SELECT   Gateway,   Company,COUNT   (*)   AS   SendNum,   COUNT(DISTINCT   Mobile)   AS   UserNum   FROM   Vi_Msg_Count   GROUP   BY   Gateway,   Company   where   Convert(varchar(10),RecvTime,121)   =   '2007-02-04 '  

帮我看看有没有什么语法错误啊?   在运行的时候提示FROM附近有错误!!谢谢啊!@

------解决方案--------------------
SELECT Gateway, Company,COUNT (*) AS SendNum,
COUNT(DISTINCT Mobile) AS UserNum
FROM Vi_Msg_Count
GROUP BY Gateway, Company
Having Convert(varchar(10),RecvTime,121) = '2007-02-04 '
------解决方案--------------------

SELECT Gateway, Company,
COUNT (*) AS SendNum,
COUNT(DISTINCT Mobile) AS UserNum
FROM Vi_Msg_Count
where Convert(varchar(10),RecvTime,121) = '2007-02-04 '
GROUP BY Gateway, Company
------解决方案--------------------
SELECT Gateway, Company,COUNT (*) AS SendNum, COUNT(DISTINCT Mobile) AS UserNum
FROM Vi_Msg_Count
where Convert(varchar(10),RecvTime,121) = '2007-02-04 '
GROUP BY Gateway, Company

------解决方案--------------------
AS 是給結果取個別名
------解决方案--------------------
Convert(varchar(10),RecvTime,121)

--
日期類型轉換成字符型
------解决方案--------------------
SELECT Gateway, Company,COUNT (*) AS SendNum, COUNT(DISTINCT Mobile) AS UserNum FROM Vi_Msg_Count GROUP BY Gateway, Company where Convert(varchar(10),RecvTime,121) = '2007-02-04 '
--呵呵,上面都说写过了,就不写了,楼主主要是把where 位置放错了,
where Convert(varchar(10),RecvTime,121) = '2007-02-04 '
应该放到GROUP BY Gateway, Company前面,GROUP BY Gateway, Company 后面是用having
------解决方案--------------------
用order by