SELECT t.*,a.* FROM discuz1.cdb_threads t INNER JOIN discuz1.cdb_attachments a ON t.tid=a.tid WHERE a.isimage=1 and t.attachment=1 group by t.tid ORDER BY t.views DESC
就是上面的语句,
discuz1.cdb_threads,discuz1.cdb_attachments 这两个为主题表和附件表,discuz1为我的论坛数据库,cdb为数据表前缀,threads和attachments就不用我说了。
t.tid代表thread表里面的tid,同理为a.tid;a.isimage表示attachment表里面的isimage字段,用于判断附件是否为图像,1为true,0为false(这个很必要,不然有些附件不是图片调用出来会显示红X);t.attachment,估计是用于判断是否有附件的,和a.isimage一个理。
ORDER BY t.views DESC:按查看数递减排列,
SQL语句:SELECT t.*,a.* FROM discuz1.cdb_threads t INNER JOIN discuz1.cdb_attachments a ON t.tid=a.tid WHERE a.isimage=1 and t.attachment=1 group by t.tid ORDER BY t.views DESC