select max(convert(int,a18)) as a18 from [table] where tabletype in ('c7b85913-21e2-4f14-8a4d-b0374439de28','c7b85913-21e2-4f14-8a4d-b0374439de28','1ae1aa6a-79db-43d8-8550-64992099a5af','bcea9114-af09-47ac-af7d-b84c68719a5b')=======这一语句有错误吗?查不出最大数

解决方案 »

  1.   

    你后面都in了,前面还max啊?
      

  2.   

    语法没问题。select *
    from [table] 
    where tabletype in (
    'c7b85913-21e2-4f14-8a4d-b0374439de28'
    ,'c7b85913-21e2-4f14-8a4d-b0374439de28'
    ,'1ae1aa6a-79db-43d8-8550-64992099a5af'
    ,'bcea9114-af09-47ac-af7d-b84c68719a5b') 这样有结果吗?
      

  3.   


    DROP TABLE TEST
    CREATE TABLE TEST(ID INT)
    INSERT TEST 
    SELECT 1 UNION ALL
    SELECT 2 UNION ALL
    SELECT 3 UNION ALL
    SELECT 4 UNION ALL
    SELECT 5 
    GOSELECT * FROM TESTSELECT MAX(ID) FROM TEST WHERE ID IN(1,3,5)            
    ----------- 
    5(所影响的行数为 1 行)
      

  4.   

    select * from tb
    /*a           b    c
    ----------- ---- -----------
    1           x    10
    1           y    100
    1           h    30
    6           c    80
    6           z    50(5 行受影响)*/
    select max(a) from tb  where c in (10,30,50)
    /*
    -----------
    6(1 行受影响)
    */
      

  5.   

    select max(a18) as a18 
    from [table] 
    where tabletype in 
    ('c7b85913-21e2-4f14-8a4d-b0374439de28',
    'c7b85913-21e2-4f14-8a4d-b0374439de28',
    '1ae1aa6a-79db-43d8-8550-64992099a5af',
    'bcea9114-af09-47ac-af7d-b84c68719a5b') 
    这样就OK拉 
      

  6.   

    select *
    from [table] 
    where tabletype in (
        'c7b85913-21e2-4f14-8a4d-b0374439de28'
        ,'c7b85913-21e2-4f14-8a4d-b0374439de28'
        ,'1ae1aa6a-79db-43d8-8550-64992099a5af'
        ,'bcea9114-af09-47ac-af7d-b84c68719a5b') 
    这样有结果。

    select max(convert(int,a18)) as a18 from [table] where tabletype in ('c7b85913-21e2-4f14-8a4d-b0374439de28','c7b85913-21e2-4f14-8a4d-b0374439de28','1ae1aa6a-79db-43d8-8550-64992099a5af','bcea9114-af09-47ac-af7d-b84c68719a5b') 
    这样就不行,查询不出最大值,a18为varchar类型