I have a query I am trying to “convert” to mysql. Here is the query:
select top 5 *
from
(select id, firstName, lastName, sum(fileSize) as TotalBytes, sum(fileSize)/count(b.*) as Average
from roster_cs368 a
join htmp_cs3868 b on b.id = a.id
)
union
(
select id, firstName, lastName, sum(fileSize) as TotalBytes, sum(fileSize)/count(b.*) as Average
from roster_cs368 a
join atmp_cs3868 b on b.id = a.id
)
order by TotalBytes desc
I am hoping someone can show me the “mysql: way of doing it. I really appreciate it. This is part of a Java program I am doing and not very familiar with sql queries as of yet.
UPDATE:
mysql> select * from roster_cs368
-> ;
+--------+-----------+-----------+
| id | firstName | lastName |
+--------+-----------+-----------+
| apn7cf | Allen | Newton |
| atggg3 | andrew | goebel |
| aysfgd | Alfred | Santos |
| cdq6c | chris | declama |
where “id” is the primary key
mysql> select * from htmp_cs368;
+------------+----------+------------+----------+----------+-------+------+-------+----------------------+
| filePerms | numLinks | id | idGroup | fileSize | month | 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 |
no primary key here,
and the last table:
mysql> select * from atmp_cs368;
+------------+----------+--------------+----------+----------+-------+------+-------+-----------------------------+
| filePerms | numLinks | id | idGroup | fileSize | month | 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 |
| drwx---rwx | 26 | antognolij | sasl | 1683 | Nov | 12 | 14:00 | 401 |
no primary key here either.
The query I am to answer is:
produce a list of the five members of roster_cs368
and their ids who use the most space (number of bytes)
in htmp_cs368 and atmp_cs368 in descending order--
greediest first.
Hope this info helps. Please note, there is much more information in the tables then presented. What is here is just a snippet.
As documented under
SELECTSyntax:Therefore:
Note that
id,firstNameandlastNameare hidden columns, the values of which are indeterminate unless the same for every record.