嗨,伙计,我正在从我的表格中选择我的活动记录,我的所有其他记录都很好,但是活动记录给了我错误我的代码是
@query = Estate.find_by_sql"SELECT (e.name) as estate_name, g.name asGovernance_body,"+ "(select count( ) from stand s where s.estate_id = e.id AND #{filter_estates}) as total_stands, "+ "(select e.active from states e where e.active = true AND #{filter_estates}) as Estate_status, "+ "(select count( ) from services sp where sp.estate_id = e.id AND #{filter_estates} ) as service_providers,"+ "(select count(*) from approved_vendors av where av.estate_id = e.id AND #{filter_estates})as vendor"+ " FROM states e LEFT JOINGoverning_bodies g on e.governing_body_id = g.id和 #{filter_states} "
我得到一个错误。
(Mysql::Error: Subquery return more than 1 row: SELECT (e.name) as estate_name, g.name asGovernance_body,(select count( ) from stand s where s.estate_id = e.id AND e.id IS NOT NULL)作为total_stands,(从estates e中选择e.active,其中e.active = true AND e.id IS NOT NULL)作为estate_status,(从服务sp中选择count(),其中sp.estate_id = e.id AND e.id不为空)作为service_providers,(从approved_vendors av 中选择计数(*),其中av.estate_id = e.id AND e.id 不为空)作为来自庄园的供应商e LEFT JOINGovernance_bodies g on e.governing_body_id = g.id AND e.id 不为空):
我想显示所有活跃和不活跃的庄园。
请问各位,我该如何解决这个问题。我正在使用 Mysql 数据库。