销售总额

时间:2016-01-17 23:02:34

标签: sql firebird2.5

我想选择商品并总结他们的销售和价格,如:

Produkt Sales   Price
Car1    1       100
Car1    2       120
Car1    3       110
Car2    1       200
Car2    2       210

结果应为

Produkt Sales   Price
Car1    6       330
Car2    3       410

我知道sum函数,但是我不知道如何选择simular Cars来对它们进行分组以对数字求和。

2 个答案:

答案 0 :(得分:1)

您只需override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { var indexpath : NSIndexPath = self.tableView.indexPathForSelectedRow! var destViewController = segue.destinationViewController as! SecondView let row: Int = indexpath.row getMore(row) destViewController.nameString = namesArray[row] destViewController.companyString = companyArray[row] destViewController.homeNumber = homeNumber[row] destViewController.workNumber = workNumber[row] destViewController.mobileNumber = mobileNumber[row] destViewController.emailAddress = self.email if let url = NSURL(string: self.largeImageURL) { if let data = NSData(contentsOfURL: url) { let image1 = UIImage(data: data) destViewController.pic = image1! } } destViewController.birthday = birthDate[row] destViewController.address = self.street + self.city + self.state + self.country + self.zip } GROUP上的结果,并使用produkt汇总函数计算每个组的sum()sales

这是ANSI SQL,因此它不仅适用于prices

Firebird

答案 1 :(得分:0)

SELECT Produkt, SUM(Sales) AS Total_sales, SUM(Price) as Total_price
FROM table_name --Your table name here
GROUP BY Produkt
ORDER BY Produkt

试试这个SQL