0
我一直拉着我的頭髮來解決這個問題..我可以將其轉換爲varchar並將%符號添加到結果?如何轉換爲varchar並將%符號添加到SQL
我已經將下面的代碼放在查詢中,並試圖將其轉換,但不斷收到我不知道如何解決的錯誤。有人可以提出一些建議,如何簡化和防止零問題的分歧。
select 'Conversion Rate' as Type,
(
SELECT
(
COALESCE
(
CAST(CAST(nullif(t.ConvertedTrials,0) AS NUMERIC(18,2))/(CAST(nullif(t.UnconvertedTrials,0) AS NUMERIC(18,2))) * 100 as decimal(10,2))
,
0
)
) AS Percentage
FROM (
SELECT
UnconvertedTrials = (
SELECT count(*) FROM
(
select memberid from membership where discountcodeid = '79a7fd7c-9ebe-4ec0-8ac0-95ea274f1f64' Group by membership.memberid
) as a
),
ConvertedTrials = (
SELECT count(*) FROM
(
SELECT membership.memberid
FROM Membership, Package
WHERE membership.PackageId = Package.Id
AND Package.PackageTypeId != 1
AND membership.memberid in (select memberid from membership where discountcodeid = '79a7fd7c-9ebe-4ec0-8ac0-95ea274f1f64')
Group by membership.memberid
) as b
)
) as t
) as Total
你能展示你的結果會是什麼樣子嗎?另外,你得到的錯誤是什麼? –
鑄造代碼是什麼樣的?另外,儘管你可以給字符串添加一個百分比符號,但對於這些數據的目的地而言,這確實更令人擔憂。這是一個顯示任務。 –