我做错什么了?如果单身人数多于已婚人数,它需要显示“是”,如果是维切弗萨,则显示“否”。我只想显示是或否。

IF
select COUNT(StudMaritalStatus) from students WHERE StudMaritalStatus = "M"
<
select COUNT(StudMaritalStatus) from students WHERE StudMaritalStatus = "S"
Print 'Yes'
ELSE
Print 'No';

最佳答案

考虑到MySQL使用:

 IF expression THEN
      expression
    ELSE
 ENDIF;

最好不要用select语句
DECLARE married int, single int

SET married = select COUNT(StudMaritalStatus) from students WHERE StudMaritalStatus = 'M'

SET single = select COUNT(StudMaritalStatus) from students WHERE StudMaritalStatus = 'S'

IF married < single THEN
  PRINT 'YES'
ELSE
  PRINT 'NO'
END IF

回答是的,你的语法错了
https://dev.mysql.com/doc/refman/5.7/en/if.html

10-07 21:06