我有这个mysql查询:
SELECT Files.GUID, Files.Name, Files.Type, Files.Visibility, Files.CreationDate, Files.OwnerUser, Date, BackupsCount
FROM Files
LEFT JOIN (
SELECT FileGUID, Date, COUNT(*) AS BackupsCount
FROM Versions
GROUP BY FileGUID
) Versions ON Files.GUID = Versions.FileGUID
WHERE Files.ParentFolder = '96251A8B-B2A8-416B-92D7-3509E6A645C7'
ORDER BY Files.Type DESC, CreationDate ASC
LIMIT 0, 50
我想知道如果 LIMIT 指令不存在,这个查询将返回多少条记录,我用谷歌搜索发现我需要添加SELECT SQL_CALC_FOUND_ROWS
和SELECT FOUND_ROWS();
我的问题是:我无法让它工作:
SELECT SQL_CALC_FOUND_ROWS * FROM (
SELECT Files.GUID, Files.Name, Files.Type, Files.Visibility, Files.CreationDate, Files.OwnerUser, Date, BackupsCount
FROM Files
LEFT JOIN (
SELECT FileGUID, Date, COUNT(*) AS BackupsCount
FROM Versions
GROUP BY FileGUID
) Versions ON Files.GUID = Versions.FileGUID
WHERE Files.ParentFolder = '96251A8B-B2A8-416B-92D7-3509E6A645C7'
ORDER BY Files.Type DESC, CreationDate ASC
LIMIT 0, 50)
-- Find total rows
SELECT FOUND_ROWS()
假设这是个好主意(我的意思是做一个查询而不是两个单独的查询),我怎样才能让FOUND_ROWS()
这个查询工作?