我有一个表,其主键是由3列组成的复合表:
userID FK of users table
itemID FK of items table
itemType FK of itemtypes table主键是(userID,itemID,itemType )的组合
假设: itemID 1是一个球,itemType 1是黑色。
在下面的例子中,
User 1 is selecting a BALL which is BLACK
User 2 is selecting a BALL which is WHITE
User 3 is selecting a BALL which is BLACK
+------+------+--------+
|userID|itemID|itemType|
+------+------+--------+
| 1 | 1 | 1 |
+------+------+--------+
| 2 | 1 | 2 |
+------+------+--------+
| 3 | 1 | 1 |现在我要计算所有选择黑球的用户,如何计算这个表的主键,即复合键。
谢谢你的进阶。
发布于 2013-12-06 13:31:55
若要计数所有选择黑球的用户,请尝试以下查询:
SELECT COUNT(userID)
FROM table1
WHERE itemID = 1 AND itemType = 1我不知道你所说的“我如何计算这张表的主键”是什么意思。
https://stackoverflow.com/questions/20425167
复制相似问题