日期:2014-05-18 浏览次数:20504 次
select qestionID,choiceID,COUNT(qestionID) as personCount from T_Questionnaire group by qestionID,choiceID
------解决方案--------------------
其实这个最好用函数如果数据库支持的话。
如果用单条SQL可以这样:
SELECT COUNT(DISTINCT biaoNO)
FROM [表名] AS t1 JOIN [表名] AS t2 ON t1.biaoNO = t2.biaoNO
WHERE t1.QuestionID = 1 and t1.RepID=2 and t2.QuestionID = 3 and t2.RepId=4
如果支持复合语句的话可以
SELECT COUNT(DISTINCT biaoNO)
FROM [表名]
WHERE biaoNO IN
(
SELECT DISTINCT biaoNO
FROM [表名]
WHERE QuestionID = 1 and RepID = 2
)
and QuestionID=3 and RepID=4
------解决方案--------------------
这个得用函数 存储过程 或者前端动态构造SQL语句啊