我的任务是处理我遇到问题的查询。这是查询:
给定用户 ID 和月份,生成一个包含学生姓名、他们拥有的文件列表(从大到小)的列表,包括文件总数和指定月份中使用的字节数。
这是我到目前为止所拥有的:
(Select * from htmp_cs368
Join roster_cs368 ON htmp_cs368.userId =
roster_cs368.lastName Where htmp_cs368.userId =
(SELECT lastName FROM roster_cs368 WHERE userId = 'userId' AND htmp_cs368.monthIn = 'monthIn'))
UNION
(Select * from atmp_cs368
JOIN roster_cs368 ON atmp_cs368.userId =
roster_cs368.userId Where roster_cs368.userId =
'userId' AND atmp_cs368.monthIn = 'monthIn') ORDER BY fileSize DESC;
我得到一个空集的结果。我的桌子满了。我希望有人能纠正我的错误。
我已经包含了我的架构:
mysql> select * from roster_cs368
-> ;
+--------+-----------+-----------+
| userId | firstName | lastName |
+--------+-----------+-----------+
| apn7cf | Allen | Newton |
| atggg3 | andrew | goebel |
主键是 userId
mysql> select * from htmp_cs368;
+------------+----------+------------+----------+----------+-------+------+-------+----------------------+
| filePerms | numLinks | userId | idGroup | fileSize | monthIn | day | time | fileName |
+------------+----------+------------+----------+----------+-------+------+-------+----------------------+
| drwx------ | 2 | schulte | faculty | 289 | Nov | 7 | 2011 | Java |
| -rw-r--r-- | 1 | schulte | faculty | 136 | Apr | 29 | 2012 | LD |
| drwxr-xr-x | 3 | schulte | faculty | 177 | Mar | 20 | 2012 | Upgrade |
这里没有主键
select * from atmp_cs368;
+------------+----------+--------------+----------+----------+-------+------+-------+-----------------------------+
| filePerms | numLinks | userId | idGroup | fileSize | monthIn | day | time | fileName |
+------------+----------+--------------+----------+----------+-------+------+-------+-----------------------------+
| drwxr-xr-x | 2 | remierm | 203 | 245 | Sep | 17 | 14:40 | 148360_sun_studio_12 |
| drwx---rwx | 31 | antognolij | sasl | 2315 | Oct | 24 | 12:28 | 275 |
| -rwx------ | 1 | kyzvdb | student | 36 | Sep | 19 | 13:05 | 275hh |
这里也没有主键。
我对mysql的经验很少。我还必须提出:如果未指定用户 ID,则所有文件,如果未指定月份,则所有用户,如果未指定,则所有月份和用户。我被困住了,不知所措。我很感激任何帮助!谢谢!