开发者

Select specific info from Sqlite DB?

In my db, I have a column for date (formatted as 3-1-2011) and a column for quantity. I want to grab the quantity for all results in the specified month up to a certain day.

Currently I'm using, the following:

SELECT SUM(quantity) FROM record WHERE date LIKE '"+month+"-%-"+year+"'"

This works to get the sum quantity from all records in that month/year. Now I'm looking at getting the sum only up to the specified day. So if day = 15, I want the sum qua开发者_开发问答ntity of all days in that month/year up to the 15th. How would I go about this?


Why not do something like this:

"SELECT SUM(quantity)
 FROM record
 WHERE date IS BETWEEN '"+month+"-01-"+year+"'
                   AND '"+month+"-"+end_day+"-"+year+"'" 

As long as month and day are always stored as two digits (i.e. "03-01-2011" not "3-1-2011") this will work fine. If your data is not in this format, it shouldn't be hard to convert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜