SQLite中的好数字

时间:2017-09-25 23:35:44

标签: sql sqlite

我是SQL的新手所以请原谅我的空白区域。我正在尝试在sqlite中编写一个查询,给我两个值:

  1. 列(预算)中具有不同值的所有值的总和 从另一列(花费)并将值转换为数千, 数百万,数十亿使用k,M和B连接作为后缀
  2. 从当前日期('现在')减去截止日期(日期) 以天为单位获得价值。
  3. 这是我使用过的查询,但结果似乎有些偏差而且不准确:

    SELECT ( CASE 1 
    WHEN SUM(Budget >= 1000 AND Budget < 10000) THEN  '$' || 
    substr(Budget,1,1) || '.' || substr(Budget,2,1)  || 'K'
    WHEN SUM(Budget  >= 10000 AND Budget < 100000) THEN '$' || 
    substr(Budget,1,2) || '.' || substr(Budget,3,1)  || 'K'
    WHEN SUM(Budget >= 100000 AND Budget < 1000000) THEN '$' || 
    substr(Budget,1,3) || '.' || substr(Budget,4,1)  || 'K'
    WHEN SUM(Budget >= 1000000 AND Budget < 10000000) THEN  '$' || 
    substr(Budget,1,1) || '.' || substr(Budget,2,1)  || 'M'
    WHEN SUM(Budget >= 10000000 AND Budget < 100000000) THEN '$' || 
    substr(Budget,1,2) || '.' || substr(Budget,3,1)  || 'M'
    WHEN SUM(Budget >= 100000000 AND Budget < 1000000000) THEN '$' || 
    substr(Budget,1,3) || '.' || substr(Budget,4,1)  || 'M'
    WHEN SUM(Budget >= 1000000000 AND Budget < 10000000000) THEN  '$' || 
    substr(Budget,1,1) || '.' || substr(Budget,2,1)  || 'B'
    WHEN SUM(Budget >= 10000000000 AND Budget < 100000000000) THEN '$' || 
    substr(Budget,1,2) || '.' || substr(Budget,3,1)  || 'B'
    WHEN SUM(Budget >= 100000000000 AND Budget < 1000000000000) THEN '$' || 
    substr(Budget,1,3) || '.' || substr(Budget,4,1)  || 'B'
    ELSE ''
    END) AS budget,
    (SELECT cast(
         (
                  strftime('%d',eventDate)-strftime('%d','now')
         ) AS real
      )) AS days_left, (SELECT (count(spent)) AS total_spent FROM 
    `user_selected_items` WHERE `userID` = 'userID' 
    AND `Status` IN('0')) AS total_items_left FROM `user_selected_items`
    

0 个答案:

没有答案