1

在以下查询中,我尝试为每个类别获取一张图片

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

但不断收到以下错误:

#1241 - Operand should contain 1 column(s)

有任何想法吗 ?

4

2 回答 2

6

替换*为单列images li

于 2012-03-13T11:26:03.557 回答
0

我有一个类似的问题。您的第 3 级选择语句 ( SELECT * FROM images li) 需要返回一个值,因为第 2 级选择语句 ( SELECT id AS category_id,COALESCE( ...) 在其占位符中只需要一个值。

就我而言,它奏效了。在这里,我还将秒表 ( ) 中的数据平均SecondBasis到一分钟表 ( ) 中的值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' ;
于 2013-11-22T10:38:08.570 回答