我大约有六(6)个表,每个表都与userid链接。表之一是userinfo。用户信息包含用户详细信息,包括其商店平台(例如magento)
仅使用magento平台在userinfo表中选择用户很容易,但这意味着我可以选择仅注册但不继续在我的应用程序上创建活动的用户。
$query3 = ("SELECT COUNT(*) FROM ( SELECT userid FROM table1 UNION SELECT userid FROM table2 UNION SELECT userid FROM table3 UNION SELECT userid FROM table4 UNION SELECT userid FROM table5 ) AS UserIDs"); $result3 = mysql_query($query3) or die(mysql_error()); $row3 = mysql_fetch_row($result3); echo "Number of distinct users in all tables = ".$row3[0] ."<br />";
Table 1 Id userid name adresss
Table 2 Id Title Sex userid
Table 3 Id userid amount
Table 4 Id price promotion userid productid
Table 5 Id userid category tax weight
userinfo Id userid username password platform
从我的其他建议的子UNION选择中展开,您可以在表格中进行此选择并获得不同的计数。JOIN``UserInfo
UNION
JOIN``UserInfo
SELECT COUNT (DISTINCT ui.UserID)) FROM ( SELECT UserID FROM Table1 UNION SELECT UserID FROM Table2 UNION SELECT UserID FROM Table3 UNION SELECT UserID FROM Table4 UNION SELECT UserID FROM Table5 ) AS id INNER JOIN UserInfo ui ON ui.UserID = id.UserID WHERE ui.Platform = 'Magento'