tags:

views:

202

answers:

3

I am trying to do multiple counts everyone was working accept the first sub select (list1) I get an error that reads "Operand should contain 1 column(s)" i'm guessing it has something to do with the AND, but i'm not sure how I would fix this one.

  Select Count(list0.ustatus) AS finished_count
       ,   (Select list1.ustatus, Count(*) 
              From listofupdates list1 
             Where list1.ustarted != '0000-00-00 00:00:00' 
               AND list1.ustatus != 1
           ) AS start_count
       ,   (Select Count(list2.udifficulty) 
              From listofupdates list2 
             Where  list2.udifficulty = 2
           )  AS recheck_count
       ,   (Select Count(list3.udifficulty) 
              From listofupdates list3 
              Where  list3.udifficulty = 4
           )  AS question_count 
     From listofupdates as list0 
    Where  list0.ustatus = 1 
A: 

The problem's most likely on the lines with

FROM listofupdates listX

(where X is 0, 1, 2, 3)

It would seem that just list0, list1, list2, list3 in these cases would suffice.

incaren
+2  A: 

In the first sub-select, you're trying to select 2 columns. You need to only select one, you can't sub-select multiple columns unless you're doing a comparison with the result.

See MySQL Docs - Subquery Errors.

Chad Birch
good tip, thanks
jason
+2  A: 

i completely aggree with @Chad Birch

Following query should work.

 Select Count(list0.ustatus) AS finished_count
       ,   (Select  Count(*) 
              From listofupdates list1 
             Where list1.ustarted != '0000-00-00 00:00:00' 
               AND list1.ustatus != 1
           ) AS start_count
       ,   (Select Count(list2.udifficulty) 
              From listofupdates list2 
             Where  list2.udifficulty = 2
           )  AS recheck_count
       ,   (Select Count(list3.udifficulty) 
              From listofupdates list3 
              Where  list3.udifficulty = 4
           )  AS question_count 
     From listofupdates as list0 
    Where  list0.ustatus = 1 
Salil
worked wonderfully thank you very much!
jason