#1241 - Operand should contain 1 column(s)

喜欢而已 提交于 2019-12-02 12:35:13

问题


In the following query am trying to get one image per category

SELECT  l.*
FROM    (
   SELECT  id AS category_id,
           COALESCE(
           (
           SELECT  *
           FROM    images li
           WHERE li.category_id = dlo.id

           ORDER BY
                       li.save_status DESC, li.category_id DESC, li.id DESC
           LIMIT 1
           ), 0) AS mid
   FROM    cats_imgs dlo where id='1'
   ) lo
JOIN    images l
ON      l.save_status = '3'
   AND l.category_id >= lo.category_id
   AND l.category_id <= lo.category_id
   AND l.id >= lo.mid

but keep getting the following error :

#1241 - Operand should contain 1 column(s)

Any ideas ?


回答1:


replace * with a single column for images li




回答2:


I had a similar problem. Your 3rd level select statement (SELECT * FROM images li) needs to return a single value, since the 2nd level select statement (SELECT id AS category_id,COALESCE( ...) is expecting only one value in its place holder.

For my case, it worked. Here I also averaged the data from a second based table (SecondBasis) to the values in the one minute basis table (MinuteBasis):

SELECT MinuteBasis.time, MinuteBasis.avg_t, MinuteBasis.avg_p,MinuteBasis.avg_t2,
  (SELECT avg(SecondBasis.m1)
   FROM SecondBasis
   WHERE SecondBasis.time BETWEEN MinuteBasis.time AND addtime (MinuteBasis.time,'0 0:00:59'))
  (SELECT avg(SecondBasis.m2)
   FROM SecondBasis
   WHERE SecondBasis.time BETWEEN MinuteBasis.time AND addtime (MinutBasis.time,'0 0:00:59'))
FROM MinuteBasis
WHERE MinuteBasis.time BETWEEN '2012-05-02 8:30:00' AND '2012-05-02 8:44:59' ;


来源:https://stackoverflow.com/questions/9682993/1241-operand-should-contain-1-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!