douji1999 2014-01-24 19:02
浏览 35

PHP mysql计算2列之间

I want to calculate how much percentage is positive and negative for voting. For instance, I have like 5 positive and 5 negative votes it should make it 50%, right?

How can i do that in a mysql/php query?

The columns are like this:

no yes yes no no no no yes yes yes

  • 写回答

1条回答 默认 最新

  • drtiwd06558 2014-01-24 19:05
    关注
    select id, 
           100 * sum(vote_column = 'yes') / count(vote_column) as percentage
    from your_table
    group by id
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo