我们在数据库中有一个动态查询,如下所示,我们正在传递Number列来对数据进行排序,但是由于某种数字格式和货币,它无法正常工作。
以下是我们的示例查询。
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet=1.12.7-00 kubeadm=1.12.7-00 kubectl=1.12.7-00
我们想通过使用列号来进行上述查询,但无法使用列名进行排序,请提出建议。
答案 0 :(得分:0)
尝试一下
Select * from (
SELECT
dbo.FormatAmountforCustomQuery(FORMAT(SUM(pcptlc.Value),'N')) AS [Planned]
,dbo.FormatAmountforCustomQuery(FORMAT((REPLACE(REPLACE([Committed],',',''),'$','') - SUM(pcptlc.Value)),'N')) AS [To Be Planned]
,dbo.FormatAmountforCustomQuery(FORMAT(SUM(pcptla.Value),'N')) AS [Actual]
,dbo.FormatAmountforCustomQuery(FORMAT((REPLACE(REPLACE([Committed],',',''),'$','') - SUM(pcptla.Value)),'N')) AS [Remaining]
from XPV.MyFIlterView d1
) as FilteredView
ORDER BY 1,4 DESC
您还可以与Clouse一起使用
WITH FilteredView AS (
SELECT
dbo.FormatAmountforCustomQuery(FORMAT(SUM(pcptlc.Value),'N')) AS [Planned]
,dbo.FormatAmountforCustomQuery(FORMAT((REPLACE(REPLACE([Committed],',',''),'$','') - SUM(pcptlc.Value)),'N')) AS [To Be Planned]
,dbo.FormatAmountforCustomQuery(FORMAT(SUM(pcptla.Value),'N')) AS [Actual]
,dbo.FormatAmountforCustomQuery(FORMAT((REPLACE(REPLACE([Committed],',',''),'$','') - SUM(pcptla.Value)),'N')) AS [Remaining]
from XPV.MyFIlterView d1
)
SELECT * FROM FilteredView
ORDER BY 1,4 DESC