假设我具有以下表格结构:
t1 ------------- id // row id userID_follower // this user is a follows another member userID_following // other member that this user
是否可以运行单个查询以结合以下两个条件:
从t1 WHERE userID_follower =“。$ myID”中选择COUNT(id)。。”
从t1 WHERE userID_following =“。$ myID”中选择COUNT(id)。
谢谢。
在MySql中,您可以SUM()在条件上使用该函数,因为错误条件将等于0,而真正条件将等于1:
SUM()
0
1
SELECT SUM(userID_follower = $myID) AS followerCount, SUM(userID_following = $myID) AS followingCount FROM t1 WHERE userID_follower = $myID OR userID_following = $myID