Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子查询被自动添加了ifnull,并且备用值为0,与返回值类型不一致 #1140

Closed
ANCB520 opened this issue Jun 2, 2022 · 2 comments

Comments

@ANCB520
Copy link
Collaborator

ANCB520 commented Jun 2, 2022

var t = SqlService.Db.Select<LocationEntity>().LeftJoin(o => o.Id == o.GDAddress.LocationId) .Where(o => o.CollectTime == SqlService.Db.Select<LocationEntity>().As("b").Where(b=>b.DeviceCode == entity.DeviceCode).Max(b => b.CollectTime)) .First();

生成的SQL为

SELECT a.Id, a.Version, a.IsDeleted, a.CreatedTime, a.ModifiedTime, a.DeviceCode, a.Latitude, a.Longitude, a.Altitude, a.IsFromMockProvider, a.CollectTime, a.FormattedAddress, a__GDAddress.Id as13, a__GDAddress.Version as14, a__GDAddress.CreatedTime as15, a__GDAddress.LocationId, a__GDAddress.GdLatitude, a__GDAddress.GdLongitude, a__GDAddress.FormattedAddress as19, a__GDAddress.Country, a__GDAddress.Province, a__GDAddress.City, a__GDAddress.Citycode, a__GDAddress.District, a__GDAddress.Adcode, a__GDAddress.Township, a__GDAddress.Towncode
FROM Location a
LEFT JOIN GDAddress a__GDAddress ON a.Id = a__GDAddress.LocationId
WHERE (a.CollectTime = ifnull((SELECT max(b.CollectTime)
FROM Location b
WHERE (b.DeviceCode = '7678f598-3f8e-4e8c-90ee-dcd3c3041388') AND (b.IsDeleted = 0)), 0)) AND (a.IsDeleted = 0)
limit 0,1

因为fnull备用值为0,子查询返回数据的数据类型为DATETIME
导致
Incorrect DATETIME value: '0'

@2881099
Copy link
Collaborator

2881099 commented Jun 2, 2022

收到,晚上解决

@ANCB520
Copy link
Collaborator Author

ANCB520 commented Jun 3, 2022

哈哈,这效率没话说

@ANCB520 ANCB520 closed this as completed Jun 3, 2022
2881099 added a commit that referenced this issue Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants