有如此查询结果bcl bzl bqzs year
100 200 300 2009
查询语句如下:select avg(bcl_jqpj) as bcl1,avg(bzl_jqpj) as bzl,avg(bqzs_jqpj) as bqzs,2009 as year from GX_HB_NZWZYBHTJDCQKB_D where recordid in (
select recordid from GX_HB_NZWZYBHTJDCQKB where sxbm in ('452001','452002','452003')
) and dcrq >= timestamp '2009-11-01 00:00:00' and dcrq <= timestamp '2009-12-15 00:00:00'bcl bzl bqzs year
311 14 6 2008
查询语句如下:select avg(bcl_jqpj) as bcl2,avg(bzl_jqpj) as bzl,avg(bqzs_jqpj) as bqzs,2008 as year from GX_HB_NZWZYBHTJDCQKB_D where recordid in (
select recordid from GX_HB_NZWZYBHTJDCQKB where sxbm in ('452001','452002','452003')
) and dcrq >= timestamp '2008-11-01 00:00:00' and dcrq <= timestamp '2008-12-15 00:00:00'bcl bzl bqzs year
89 1098 45 2007
查询语句如下:select avg(bcl_jqpj) as bcl3,avg(bzl_jqpj) as bzl,avg(bqzs_jqpj) as bqzs,2007 as year from GX_HB_NZWZYBHTJDCQKB_D where recordid in (
select recordid from GX_HB_NZWZYBHTJDCQKB where sxbm in ('452001','452002','452003')
) and dcrq >= timestamp '2007-11-01 00:00:00' and dcrq <= timestamp '2007-12-15 00:00:00'现在我想从以上三个查询结果中得到这样的结果。bcl_max year bzl_max year bqzs_max year
311 2008 1098 2007 300 2009
就是说,去得每个字段最大值及所对应的年份。求sql
100 200 300 2009
查询语句如下:select avg(bcl_jqpj) as bcl1,avg(bzl_jqpj) as bzl,avg(bqzs_jqpj) as bqzs,2009 as year from GX_HB_NZWZYBHTJDCQKB_D where recordid in (
select recordid from GX_HB_NZWZYBHTJDCQKB where sxbm in ('452001','452002','452003')
) and dcrq >= timestamp '2009-11-01 00:00:00' and dcrq <= timestamp '2009-12-15 00:00:00'bcl bzl bqzs year
311 14 6 2008
查询语句如下:select avg(bcl_jqpj) as bcl2,avg(bzl_jqpj) as bzl,avg(bqzs_jqpj) as bqzs,2008 as year from GX_HB_NZWZYBHTJDCQKB_D where recordid in (
select recordid from GX_HB_NZWZYBHTJDCQKB where sxbm in ('452001','452002','452003')
) and dcrq >= timestamp '2008-11-01 00:00:00' and dcrq <= timestamp '2008-12-15 00:00:00'bcl bzl bqzs year
89 1098 45 2007
查询语句如下:select avg(bcl_jqpj) as bcl3,avg(bzl_jqpj) as bzl,avg(bqzs_jqpj) as bqzs,2007 as year from GX_HB_NZWZYBHTJDCQKB_D where recordid in (
select recordid from GX_HB_NZWZYBHTJDCQKB where sxbm in ('452001','452002','452003')
) and dcrq >= timestamp '2007-11-01 00:00:00' and dcrq <= timestamp '2007-12-15 00:00:00'现在我想从以上三个查询结果中得到这样的结果。bcl_max year bzl_max year bqzs_max year
311 2008 1098 2007 300 2009
就是说,去得每个字段最大值及所对应的年份。求sql
解决方案 »
- 新建数据库问题
- 特急!邹大哥请进:异类查询要求为连接设置 ANSI_NULLS 和 ANSI_WARNINGS 选项。这将确保一致的查询语义。请启用这些选项,然后重新发出查
- 一个触发器问题,Deleted无效?
- 客户要求数据库管理员不能查看系统的数据库
- 求join关系的sql语句!请进!
- SQL 2000中MSSQLSERVER服务不能启动???
- REPORT SERVER
- 新装的SQL SERVER 2005时快时慢
- 我用VB+SQL SERVER编程,请问一个连接是不是就对应SQL SERVER的一个线程?如果是要如何获得本线程的id号及连接的计算机名?
- 请问哪里有JAVA+JDBC+SQL Server连接应用的简明教程??急
- BOM配方问题(如何跟据生产数得到所有原料数)
- SQL语句加上WHERE和GROUP BY无法执行
3表结果union all
然后用聚合函数max求最值