如何将SELECT查询中的行为值?" R6 s4 t5 S9 [8 t
SELECT FUCNTIONIMLOOKINGFOR(SELECT * FROM anothertable) AS count FROM table;所以这个计数是子查询SELECT * FROM anothertable返回行数的整数。' d' d- y0 `$ ^5 S 编辑3 G; T6 x3 Q7 w! Z9 A; t$ N
SELECT p.PostPID,p.PostUID,p.PostText,p.PostTime,u.UserUID,u.UserName,u.UserImage,u.UserRep, ( SELECT COUNT(f.FlagTime) FROM Flags as f JOIN Posts as p ON p.PostPID = f.FlagPID ) as PostFlags FROM Posts AS p JOIN Users AS u ON p.PostUID = u.UserUID ORDER BY PostTime DESC LIMIT30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、30、 ; a7 b% o$ x- L# t% e0 }解决方案: 9 E! D: S1 f5 b m# ?8 y* j SELECT ( SELECT COUNT(id) FROM aTable ) as count FROM table我假设你的例子是你实际查询的截断版,所以也许你应该发布你想要的,以获得更理想的查询。, F3 M5 R9 R3 M* g/ K8 }1 Q 编辑 ! z. J& p) }4 C直接从我的大脑工作应该更理想。 8 P1 H/ `9 h* Y4 y( WSELECT p.PostPID,p.PostUID,p.PostText,p.PostTime,u.UserUID,u.UserName,u.UserImage,u.UserRep,COUNT(v.FlagTime) as postFlags FROM Flags as f JOIN Posts as p ON p.PostPID = f.FlagPID JOIN Users AS u ON p.PostUID = u.UserUIDLIMIT 0,30GROUP BY p.PostPIDORDER BY PostTime DESC