select decode(lottype,'BL',min(confirm_ship_date),max(confirm_ship_date))
from aaa
GROUP by custdevice
结果报错,一定要
GROUP by custdevice,lottype才行,是不是decode如果是聚合函数,GROUP by 这里就不用lottype了?
2.我想用select选出lottype的类型,怎么写?我是oracle数据库
select type(lottype)
from aaa还有,lottype这个叫什么?字段?列值?

解决方案 »

  1.   

    看到熟人了。。
    1. 错误是必然的
    decode(lottype,'BL',min(confirm_ship_date),max(confirm_ship_date)) 
    decode里后面的都没问题
    如果不用lottype分组的话,就给lottype加上一个聚合函数,比如max(lottype)
    或者decode里面都不用聚合,把整个decode聚合一下2.字段名,列名
    select * from user_tab_cols where table_name=upper('tablename') and column_name=upper('colname')
      

  2.   

    查看栏位的信息:
    desc aaa 
    就可以看表中所有栏位的类型了你是以lottype来分组的呀,所以一定在GROUP by后加上lottype栏位
      

  3.   


    2.我想用select选出lottype的类型,怎么写?我是oracle数据库
    select type(lottype)
    from aaa 
    你要得到lottype的类型,应该要到数据字典表里面才有像 dba_tab_cols/user_tab_cols 里面的DATA_TYPE这个字段
      

  4.   

    select decode(lottype,'BL',min_date,max_date) 
    from 
    (select min(confirm_ship_date) as confirm_ship_date min_date,max(confirm_ship_date) as  max_date
    from aaa 
    GROUP by custdevice
    ) aa 2.我想用select选出lottype的类型,怎么写?我是oracle数据库 
    select type(lottype) 
    from aaa 
    --
    select lottype
    from aaa 
    groupo by lottype
      

  5.   


    主要是group by导致的,由于有分组,所以对不在group by里的字段只能用统计方法,select decode(lottype,'BL',min(confirm_ship_date),max(confirm_ship_date))
     from aaa
     GROUP by custdevice而lottype步骤group by里所以出错 GROUP by custdevice,lottype
    lottype已经在分组里了,所以可以正确
      

  6.   

    你没替换里面的表名和列名吧...
    select * from user_tab_cols where table_name=upper('aaa') and column_name=upper('lottype')
      

  7.   

    当然替换啦。。出来这么个东西:
    TABLE_NAME COLUMN_NAME DATA_TYPE DATA_TYPE_MOD DATA_TYPE_OWNER DATA_LENGTH DATA_PRECISION DATA_SCALE NULLABLE COLUMN_ID DEFAULT_LENGTH DATA_DEFAULT NUM_DISTINCT LOW_VALUE HIGH_VALUE DENSITY NUM_NULLS NUM_BUCKETS LAST_ANALYZED SAMPLE_SIZE CHARACTER_SET_NAME CHAR_COL_DECL_LENGTH GLOBAL_STATS USER_STATS AVG_COL_LEN CHAR_LENGTH CHAR_USED V80_FMT_IMAGE DATA_UPGRADED HIDDEN_COLUMN VIRTUAL_COLUMN SEGMENT_COLUMN_ID INTERNAL_COLUMN_ID HISTOGRAM QUALIFIED_COL_NAME
      

  8.   

    应该会出现一行记录才对
    你检查下表名和列名是否书写正确
    用select lottype from aaa
    查询是否正常
      

  9.   

    用select lottype from aaa 
    是正确的 ,
      

  10.   

    你是不是在条件的字符串里多加了空格什么的
    要不把user_tab_cols改成dba_tab_cols试试
    不可能没结果的
      

  11.   

    select * from user_tab_cols 
    出来就是空的 和之前的值一样 
      

  12.   


    不是吧
    这个用户根本就没有表
    你用select * from aaa看看能查出东西来不