今天在写MySQ的SQL语句的时候遇到了一个奇怪的问题 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') GROU…
格式:IF(Condition,A,B) 意义:当Condition为TRUE时,返回A:当Condition为FALSE时,返回B. 作用:作为条件语句使用. select if(`from_user_id`='4','0','1') olr,l.* from `lm_user_lock` l order by olr; 此sql把根据from_user_id等于不等于4,加了个伪列olr,并根据olr排序(吊炸天)…
as tjsl from fyxx group by zt,whbmbh end) as ybhsl from fyxx group by whbmbh 下面是摘自别人的博客 最近遇到一个问题,需要对一张表做统计,这个统计有什么特别之处值得我记录了下来呢?大家知道SQL中聚合函数GROUP BY的结果一般为一列,即多个值通过聚合函数运算统计到一起,但是如何将不同条件的值统计到不同列中呢,即按条件统计到多个列中.举个栗子: YEAR TYPE VALUE 2015 1 100 2015 2 200…
select whbmbh ,zt,1 as tjsl from fyxx group by zt,whbmbh select whbmbh,sum(case zt when '有效' then 1 end) as yxsl,sum(case zt when '暂缓' then 1 end )as zhsl,sum(case zt when '未知' then 1 end) as wzsl,sum(case zt when '我租' then 1 end) as wzsl,sum(case zt…