zoukankan      html  css  js  c++  java
  • MySql中对Group by后的结果数进行Count

    今天在写MySQ的SQL语句的时候遇到了一个奇怪的问题

    1 select count(*) from subsitealbum t1, photo t2,files t3 
    2           where t1.SourceAlbumId = t2.FolderId 
    3           and t2.ID = t3.ID 
    4           and t2.FolderId = t3.FolderID 
    5           and SiteId in (select SubsiteID from channelsubsites where ChannelID='yszw') 
    6     GROUP BY t1.Title,t1.Author, t3.Location,t2.CName,t2.LName,t3.Name

    查询结果如下

    改为以下语句后运行正常

    select count(*) count from (select count(*) from subsitealbum t1, photo t2,files t3 
              where t1.SourceAlbumId = t2.FolderId 
                 and t2.ID = t3.ID 
                and t2.FolderId = t3.FolderID 
               and SiteId in (select SubsiteID from channelsubsites where ChannelID='yszw') 
              GROUP BY t1.Title,t1.Author, t3.Location,t2.CName,t2.LName,t3.Name) temp

    记得临时表一定要加别名,否则会报错

  • 相关阅读:
    SVN客户端的安装和使用
    SVN服务器的安装和使用
    ssh port forwarding
    mysql 索引
    ssh forwarding 配置
    pymongo collection.save 问题
    linux 实现VLAN
    linux 硬件中断调节
    M2Crypto
    python 时间四舍五入
  • 原文地址:https://www.cnblogs.com/yaotome/p/8072945.html
Copyright © 2011-2022 走看看