我是SQL的新手所以请原谅我的空白区域。我正在尝试在sqlite中编写一个查询,给我两个值:
这是我使用过的查询,但结果似乎有些偏差而且不准确:
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`