union all 返回

SqlSugar 老数据
3 2376

MYSQL 写法: 通过手机号,判断在企业表和用户表中是否存在。

select sum(C) as `Sum` from (

select count(CompanyId) as C from company where MobilePhone =@Phone 

union all 

select count(UserId) as C from userinfo where LoginName = @Phone 

) as R


这种在ORM中怎么写啊 ~.~

热忱回答3

  • Db.unionall

    0 回复
  • image.png

    按照Db.unionall实现的话,就报这个错误。因为连接的2个不同的实体(企业表和用户表)。在SQL中 我能image.png这样写,拿到想要的数据。在SqlSugarCore里,image.png就是分2次查询,最后在程序里判断。

    0 回复
  • Select 的类型一样就可以了

    0 回复