pbdesigner(MIS/ERP开发)已經搞定了.

解决方案 »

  1.   

    select 可以搞定
    select distinct ITEM_NO ,...., min(price) from table group by ITEM_NO 
      

  2.   

    to mfj():
    你確實錯了.
    select distinct ITEM_NO ,...., min(price) from table group by ITEM_NO 
    這條語句會報錯的.
      

  3.   

    他的環境就是SQLServer.是Oracle也是一樣的錯.你這樣寫報的錯是:
    Column  VENDOR_NO  is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.為什麼呢.
    因為SQLServer不能確定是那個值的VENDOR_NO.
      

  4.   

    在sql server中不可能出错!
      

  5.   

    你自己試一遍吧.
    先建張表,然後插8條紀錄,然後再run你的語句.
    你看看會不會報我剛才貼的錯誤.如果不報錯,我這輩子就不玩數據庫了.
      

  6.   

    三个看似简单的问题。 mfj() 兄弟 您真的错了。
      

  7.   

    如果只是這樣.
    select distinct ITEM_NO, min(price) from table group by ITEM_NO  
    是可以通過的,而且distinct都可以不要.
    但是還有一個VENDOR_NO是通過分組和distinct都不能造成唯一值的.
    而ITEM_NO和min(price)按ITEM_NO分組後都是每組的唯一的值.
    因此語法上就不能通過.
      

  8.   

    sorry,刚才专门装了一个sql server试了试,的确,两个column是可以,多个后则有错误!不过
    ,我想应该可以通过表的进一步细分来解。
      

  9.   

    select * from table where (item_no,price) in (select item_no,min(price) from table group by item_no)
      

  10.   

    select distinct item_no,VENDOR_NO,PRICE
     from table where item_no in (select item_no,min(price) from table group by item_no)
      

  11.   

    db2_seeker(小顺)  用的是什么数据库,  我的是SQL Server
      

  12.   

    你的要求没写清楚,db2_seeker(小顺)应该用的是ORACLE,但他写的会显示出两条最小price的记录,但你没有说明应该显示出哪个verdor_no的min(price)的记录。
    create table test (
    item_no number(9,0) not null, 
    verdor_no varchar2(10) not null,
    price number(9,2) not null,
    other_column number(9,0));insert into test(
    item_no  , 
    verdor_no ,
    price )
    values( 1, 'v1000', 2);
    insert into test(
    item_no , 
    verdor_no ,
    price )
    values( 2, 'v2000', 6);
    insert into test(
    item_no , 
    verdor_no ,
    price )
    values( 3, 'v3000', 5);
    insert into test(
    item_no  , 
    verdor_no  ,
    price )
    values( 4, 'v4000', 7);
    insert into test(
    item_no  , 
    verdor_no  ,
    price )
    values( 5, 'v5000', 8);commit;
      select * from test a 
      where (a. price, a.item_no) in
     (select min(b.price), b.Item_no from test b
     group by b.item_no)
     order by verdor_no;
     ITEM_NO VERDOR_NO       PRICE OTHER_COLUMN
    -------- ---------- ---------- ------------
           1 v1000               2
           2 v1000               2
           1 v3000               2
    你可以在结果集上过滤得到你所要的。
      

  13.   


    一、 二 、 三 问题 全部要求SELECT 出来。(注: 一定是做得到的, 而且不很长)    现想找出一个最经典的来。例: 
    select aa.item_no,min(vendor_no),aa.price,min(aa.aa) from aa 
    where aa.item_no+convert(char(10),price) in 
    (select item_no+convert(char(10),min(price)) from aa group by item_no) 
    group by item_no,price 一个较普通的。还有更好的
          
      

  14.   

    我可能理解错了ALLTEC(荔枝)的意思,不过我觉得那样完全可以解决类似的问题了。by the way, 我用的是,哎,db2