首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

sql if else 有关问题

2012-05-09 
sql if else 问题,select count(point) from (SELECT id as magazineId,title as magazineTitle,img_p

sql if else 问题,
select count(point) from (SELECT id as "magazineId",title as "magazineTitle",img_path as "imgPath",point,hits_count from magazine where audit_status='Y' order by point desc Nulls Last) t1
这段sql结果是3,我想实现的是,如果他等于0的话,就查询 别的一段代码,反之就查询
SELECT id as "magazineId",title as "magazineTitle",img_path as "imgPath",point,hits_count from magazine where audit_status='Y' order by point desc Nulls Last这段代码


[解决办法]
示例:
SELECT IF(a1=0,na2,a1) FROM 
(SELECT COUNT(POINT) AS a1 FROM (SELECT id AS "magazineId",title AS "magazineTitle",img_path AS "imgPath",POINT,hits_count FROM magazine WHERE audit_status='Y' ORDER BY POINT DESC ) t1) a1,
(SELECT COUNT(*) AS na2 FROM a ) a2 


[解决办法]
这逻辑一条qsql完成不了 只能写存储过程 或者程序里判断

热点排行