我正在尝试从dob(DATE)计算年龄并比较年龄是否大于64,但是它在'>'附近收到错误语法错误。
下面是代码
sqlStr.Append("SELECT count(CustomerRace) as CustomerCount, CustomerRace");
sqlStr.Append("FROM Customer");
sqlStr.Append("WHERE SELECT DATEDIFF(YYYY,CustomerDOB,GETDATE()) > 64");
sqlStr.Append("GROUP BY CustomerRace");
最佳答案
像这样更改您的代码,希望对您有用。
sqlStr.Append("SELECT count(CustomerRace) as CustomerCount, CustomerRace ");
sqlStr.Append("FROM Customer ");
sqlStr.Append("WHERE DATEDIFF(YY,CustomerDOB,GETDATE()) > 64 ");
sqlStr.Append("GROUP BY CustomerRace");