-1

我有两张桌子

一个是

接收短信(比赛日期、比赛时间、关键字、短信、手机号)

另一个是

QAoptios(关键字、问题、答案选项、比赛日期、比赛时间)

我需要找到与same和sameSmsMessage具有相同值的计数。而且我还需要过滤 Receivesms.Matchdate='2012-12-25 00:00:00.000'AnsweroptionMatchdateMatchtimeKeyword

4

4 回答 4

1
SELECT 
  q.AnswerOption,
  COUNT(SmsMessage) TheCount
FROM Receivesms r
INNER JOIN QAoptions q  ON r.Matchdate = q.Matchdate
                       AND r.Matchtime = q.Matchtime
                       AND r.Keyword = q.keyword
GROUP BY q.AnswerOption;
于 2012-12-26T06:56:50.323 回答
0

试试这个

SELECT count(*) from Receivesms as a  inner join QAoptios as b on a.keyword=b.keyword
and a.matchtime=b.matchtime and a.matchdate=b.matchdate and a.value=b.answeroption
于 2012-12-26T06:56:05.547 回答
0

使用可以使用:

    select count(*) from Recievesms r,QAoptios q 
    where
    r.Matchdate = q.Matchdate 
    and
    r.Matchtime = q.Matchtime
    and
    r. Keyword =q.Keyword
    and
    r.SmsMessage = q.Answeroption;

或者

    select count(*) from from Recievesms as r
    inner join
    QAoptios as q 
    on  
    r.SmsMessage =   q.Answeroption;
于 2012-12-26T06:58:26.577 回答
0
SELECT COUNT(R.SmsMessage)
FROM Receivesms R
INNER JOIN QAoptios Q ON 
R.Keyword=Q.Keyword AND
R.Matchdate=Q.Matchdate AND
R.Matchtime=Q.Matchtime AND
R.SmsMessage=Q.AnswerOption

或者,如果要显示 AnswerQuestion,可以添加 GROUP BY 子句,如下所示:

SELECT Q.AnswerOption, COUNT(R.SmsMessage) as TheCount
FROM Receivesms R
INNER JOIN QAoptios Q ON 
R.Keyword=Q.Keyword AND
R.Matchdate=Q.Matchdate AND
R.Matchtime=Q.Matchtime AND
R.SmsMessage=Q.AnswerOption
GROUP BY Q.AnswerOption
于 2012-12-26T07:09:39.903 回答