请求生成视图的SQL语句
有一个表T1,字段有id,UCuserid,title,body,readtime等
我想生成一个视图,要求:
1.列出T1中的所有记录及字段值
2.以UCUSERID为关键字做统计,获取不同UCUSERID的记录总数
2.以UCUSERID为关键字做统计,获取不同UCUSERID的记录中,ReadTime值为NULL的记录数
我写了一段,统计是实现了,但只能列出三个字段,我想把其他字段也显示出来,应该怎么做?
------以下是我写的SQL,可以帮助说明要求
SELECT ucuserid, COUNT(*) AS R_Total, SUM(CASE ReadTime WHEN Isdate (ReadTime) THEN 1 ELSE 0 END) AS NotRead FROM T1 GROUP BY ucuserid
------
说简单一点,就是在原表的基础上,再加两个统计列,请高手指点~~
------解决方案--------------------Select A.*, B.R_Total, B.NotRead
From T1 A
Inner Join
(SELECT ucuserid, COUNT(*) AS R_Total, SUM(CASE ReadTime WHEN Isdate (ReadTime) THEN 1 ELSE 0 END) AS NotRead FROM T1 GROUP BY ucuserid) B
On A.ucuserid = B.ucuserid