I need to display values on a table which are grouped. Currently I do it manually via two SQL scripts.
Instead of applying these scripts into my dao, can I do it开发者_开发知识库 client-side somehow?
Table contents would look like this
fruit name, fruit bought, fruit sold
apple, 1, 0
apple, 0, 1
orange, 1, 0
orange, 1, 0
Desired result on html table would be.
Fruit name - Fruit bought - Fruits not bought
apples - 9 - 20
oranges - 10 - 10
I'm currently using jQuery with datatables.
It would be easier to do this at the database level to begin with:
SELECT fruitname, SUM(fruit_bought), SUM(fruit_sold)
FROM table
GROUP BY fruitname
ORDER BY fruitname
Of course, you'd need somewhere to get the original inventory level to calculate your "not sold" value, but this query would give you the sum of the bought/sold values.
精彩评论