我有以下查询,都返回一个整数的条目。
[3] pry(main)> m = 'hi'
=> "hi"
[4] pry(main)> m.extend(Chainable).as { |m| m << '!' }.as { |m| m+'?'}
=> "hi!?"
[5] pry(main)> m
=> "hi"
我想比较这些整数是否相等,但我得到MySQL错误。
答案 0 :(得分:0)
您可以将SELECT
放在他们面前:
SELECT ((SELECT COUNT(*) FROM participants WHERE `status` = 'a' AND meetid = NEW.meetid) =
(SELECT capacity FROM participants INNER JOIN rooms ON pid = room WHERE room = NEW.pid)
) as SameFlag
这假设第二个子查询只返回一个值。否则你会收到错误。此查询也可以通过多种方式重写,但上述内容似乎是对原始查询的最小更改。
编辑:
我猜你想要的更像是这样:
SELECT (p.cnt = r.capacity)
FROM (SELECT COUNT(*) as cnt FROM participants WHERE `status` = 'a' AND meetid = NEW.meetid) p CROSS JOIN
(SELECT capacity FROM rooms room = NEW.pid) r;
然而,名为room
的内容与NEW.pid
进行比较似乎很奇怪。