我有一个查询从临时表中选择数据,如下所示
SELECT Ref,
YOA,
Account,
Cert,
MIN(Unit) AS Unit,
Name
Currency,
Amount
FROM #TMP_Accounts
GROUP BY Ref,
YOA,
Account,
Cert,
Name,
Currency,
Amount
当我运行此查询时,我得到以下结果:
Ref YOA Account Cert Unit Name Currency Amount
1924403 2017 ABCXYZ PFA96417 1 US CAD 25,167,555
1924403 2017 ABCXYZ PFA96417 3 FR CAD 25,167,555.56
1924403 2017 ABCXYZ PFA96417 4 DE CAD 25,167,555.56
我坚持的事实是,当我使用MIN函数时,我想拉回单位值1的一条记录,而不是我得到3条记录。我已经逐列完成了此列,只有当我添加Amount列时才会显示其他记录。
当我做一个简单的选择*从我得到以下内容:
Ref YOA Account Cert Unit Name Currency Amount
1924403 2017 ABCXYZ PFA96417 1 US CAD 25,167,555.00
1924403 2017 ABCXYZ PFA96417 2 UK CAD 25,167,555.00
1924403 2017 ABCXYZ PFA96417 3 FR CAD 25,167,555.56
1924403 2017 ABCXYZ PFA96417 4 DE CAD 25,167,555.56
1924403 2017 ABCXYZ PFA96417 5 AU CAD 25,167,555.56
1924403 2017 ABCXYZ PFA96417 6 NZ CAD 25,167,555.56
所以我知道它被聚合到一个点,而不是我需要的最小单位值。
提前致谢
答案 0 :(得分:2)
如果您想要具有最小单位数的行,您可以使用:
select top (1) a.*
from #TMP_Accounts a
order by units;
group by
肯定会导致您的问题。它可能不适合您想要做的事情。
答案 1 :(得分:1)
根据您的解释,我认为您正在寻找这个:
SELECT *
FROM #TMP_Accounts
WHERE Unit = (SELECT MIN(Unit) FROM #TMP_Accounts)
这并不一定会返回一行,因为对于具有相同最小值的重复行,您将获得这两行。但是,您的问题并不清楚如何处理这种情况。
答案 2 :(得分:1)
另一种方法是单独加入表格
override func viewDidLoad() {
super.viewDidLoad()
super.becomeFirstResponder()
// Do any additional setup after loading the view, typically from a nib.
characterImageView.image = UIImage(named: "elegantEmma")
placeImageView.image = UIImage(named: "zombieLand")
problemImageView.image = UIImage(named: "meteor")
timeImageView.image = UIImage(named: "time")
//First random value shown on the launch
characterName.text = myStoryCharacters.randomCharacter()
placeName.text = myStoryCharacters.randomPlaces()
problemName.text = myStoryCharacters.randomProblems()
timeName.text = myStoryCharacters.randomTime()