2005年11月17日
以前只是学过having条件查询,但是在工作中从没有用过,今天和同事讨论问题时才发现原来写的很多代码都可以简化。如:投票中,我要查询票数大于3的记录时,
原来我会这样写:Select * From (Select EmployeeID,Count(AgreeFlag) As VoteNum From T_Vote Where AgreeFlag = 1)tb Where tb.VoteNum >3
实际上可以这样写:Select EmployeeID,Count(AgreeFlag) As VoteNum From T_Vote Having AgreeFlag = 1 And Count(AgreeFalg) > 3
有时可以将where和having连用,如:
Select columname1,count(*) From tablename
Where columnname = value
Group By columnname1
Having count(*) > 3

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-07-10
  • 2021-08-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案