- 论坛徽章:
- 0
|
开门见山,有如下两张表:
Table a
{
id int(11) auto_increment,
statisDay date,
softName varchar(20) not null,
downloadCount int(11) not null, # 下载量
Primary key (statisDay, softName),
Unique key (id)
}
每天会向表a中插入N条记录,N不固定。
Table b
{
id int(11) auto_increment,
statisDay date,
softName varchar(20) not null,
searchCount int(11) not null, # 搜索量
Primary key (statisDay, softName),
Unique key (id)
}
每天会向表b中插入N条记录,N也不固定。
万能的cu,我想用以下的形式把两张表中每天的Top10 记录展示出来,sql怎么写呢?
a.statisDay, a.softName, a.downloadCount, b.softName, b.searchCount
2010-05-30 aaaaa 987987 bbbb 99999
2010-05-30 ccccc 987000 dddd 99966
2010-05-30 eeeee 986387 ffffff 99944
最终的记录中,表a中softName和表b的softName不一定相同。
我的思路是:每天选出两张中的前10条记录,但是得在这10条记录前面标记上每条记录的位置排名,然后用日期和记录的位置排名来join得到最终的结果。可是如何能标记选出来的记录其位置排名呢? |
|