当前位置: 代码迷 >> Sql Server >> 一个SQL语句,帮小弟我检查一下异常,多谢!
  详细解决方案

一个SQL语句,帮小弟我检查一下异常,多谢!

热度:101   发布时间:2016-04-27 16:49:39.0
一个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