版权说明:作者:张颖希(PocketZ's Blog)出处:http://www.cnblogs.com/PocketZ本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 问题 前面已经使用了别名为查询提供更有意义的列名,而且也使用WHERE子句将一些数据排除掉,然而,我们还想在WHERE子句中引用别名. select sal as salary, comm as commission from emp w
如下查询,会抛出错误:mysql> select sal as salary, comm as commission from emp where salary < 5000;ERROR 1054 (42S22): Unknown column 'salary' in 'where clause'解决方案 将查询作为内联视图就可以就可以引用其中别名的列了:select *from ( select sal as salary, comm as commission from
如下查询,会抛出错误: mysql> select sal as salary, comm as commission from emp where salary < 5000;ERROR 1054 (42S22): Unknown column 'salary' in 'where clause' 解决方案 将查询作为内联视图就可以就可以引用其中别名的列了: select *from ( select sal as salary, comm as commission from
例如,这个表的结构: select r.* from RPDATA2016 r WHERE r.data_bbid='HY052' 如图 对于最后两列,如果是字符类型,会存在倒数第二列,是数字类型,会存在最后一列,现在要把他们放在一行,行转列.通过这种方式: SELECT sum(case r.data_lord when '0001#' then r.data_data else null end ) 序号,r.data_dataid, gs.lsbzdw_dwmc 单位名称,r1.data_