SQL乘以2个表和打印语句的值?

时间:2013-09-08 00:27:32

标签: mysql sql sql-server

从2个不同的表中计算sum(frequency * weight)之后,如果总和大于某个数字,我正在尝试打印出一个语句(下面),但我一直收到一个错误,表示total是不是有效的专栏。

任何帮助将不胜感激。 提前致谢

DECLARE @total INT

SELECT SUM(frequency * weight) AS total
  FROM WF, WW
 WHERE WF.word = WW.word

IF total > 30
BEGIN
  print 'Alert! Bullying post'
END
ELSE
BEGIN
  print'Normal Post'
END

1 个答案:

答案 0 :(得分:0)

declare @Total as Int;

select @Total = Sum( WF.Frequency * WW.Weight )
  from WF inner join
    WW on WW.Word = WF.Word;

print case when @Total > 30 then 'Alert! Bullying post!' else 'Normal post.' end;