SQLite: Get Total/Sum of Column

前端 未结 2 1134
独厮守ぢ
独厮守ぢ 2021-01-17 10:55

I am using SQLite and am trying to return the total of one column buy_price in the column TOTAL while at the same time returning all of the data. I

相关标签:
2条回答
  • 2021-01-17 11:32
    Select * from yourtable
    union
    select 'Total',
      ' ',
      ' ',
      ' ',
      sum(buy_price)
    from yourtable
    

    you can add a row on the bottom like this instead of adding a new column...

    0 讨论(0)
  • 2021-01-17 11:40

    It sounds like this is what you are looking for:

    select id,
      dt,
      pool_name,
      pool_id,
      buy_price,
      (select sum(buy_price) from yourtable) total
    from yourtable
    

    see SQL Fiddle with Demo

    0 讨论(0)
提交回复
热议问题