Each GROUP BY expression must contain at least one column that is not an outer reference

前端 未结 7 1773
-上瘾入骨i
-上瘾入骨i 2020-12-09 07:50

What am I doing wrong here? I am getting this error on:

SELECT LEFT(SUBSTRING(batchinfo.datapath, PATINDEX(\'%[0-9][0-9][0-9]%\', batchinfo.datapath), 8000),         


        
7条回答
  •  借酒劲吻你
    2020-12-09 08:48

    You can't group by literals, only columns.

    You are probably looking for something like this:

    select 
    LEFT(SUBSTRING(batchinfo.datapath, PATINDEX('%[0-9][0-9][0-9]%', batchinfo.datapath), 8000), PATINDEX('%[^0-9]%', SUBSTRING(batchinfo.datapath, PATINDEX('%[0-9][0-9][0-9]%', batchinfo.datapath), 8000))-1) as pathinfo,
    qvalues.name,
    qvalues.compound,
    qvalues.rid
     from batchinfo join qvalues on batchinfo.rowid=qvalues.rowid
    where LEN(datapath)>4
    group by pathinfo, qvalues.name, qvalues.compound
    having rid!=MAX(rid)
    

    First of all, you have to give that first expression a column name with as. Then you have to specify the names of the columns in the group by expression.

提交回复
热议问题