共享和签名查询

jdg4fx2g  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(280)

有多少份股份和签名(一直)来自以下签名桶内的请愿书:1-499500-999,1000+。
注意:如果请愿书没有签名,则不能共享
table:

目前拥有并接受任何反馈:

  1. SELECT
  2. CASE
  3. WHEN COUNT(DISTINCT t1.petition_id) < 500 THEN '1-499'
  4. WHEN COUNT(DISTINCT t1.petition_id) >= 500 AND COUNT(DISTINCT t1.petition_id) < 1000 THEN '500-999'
  5. ELSE '1000+' END AS Signature_Buckets
  6. FROM
  7. signatures t1
  8. LEFT JOIN
  9. shares t2
  10. ON
  11. t1.petition_id ON t2.petition_id
jjhzyzn0

jjhzyzn01#

这个案子的解释还不完全清楚。几行样本数据可能有助于澄清边境案件。不过,下面的查询似乎会返回所需的结果:

  1. select
  2. bucket,
  3. count(*) as signatures,
  4. sum(shares) as total_shares
  5. from (
  6. select
  7. s.petition_id,
  8. count(h.petition_id) as shares,
  9. case when count(h.petition_id) < 500 then '1-499'
  10. when count(h.petition_id) < 1000 then '500-999'
  11. else '1000+'
  12. end as bucket
  13. from signatures s
  14. left join shares h on h.petition_id = s.petition_id
  15. group by s.petition_id
  16. having count(h.petition_id) > 1
  17. ) x
展开查看全部

相关问题