2007年07月26日 星期四 19:13
class prov(models.Model):
prov=models.CharField("地区",maxlength=100)
income=models.FloatField("原保险保费收入",max_digits=12, decimal_places=2)
i_property=models.FloatField("财产险",max_digits=12, decimal_places=2)
i_life=models.FloatField("寿险",max_digits=12, decimal_places=2)
i_healthy=models.FloatField("健康险",max_digits=12, decimal_places=2)
i_unexpected=models.FloatField("人身意外伤害险",max_digits=12,
decimal_places=2)
pub_date=models.DateField("日期")
我现在要实现在一段时间内的各种收入的合计,用sql 是这样的:
select prov,sum(income) as income_all,sum(i_property) as
i_property_all,.....
from prov
where pub_date between (begin_date,end_date)
group by prov
请问用django的db-api怎么实现,或者能否向hibernet那样直接使用SQL语句呢?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070726/cf9bcc98/attachment.html
2007年07月26日 星期四 19:46
django.db.connection.cursor().execute(' sql ')
On 7/26/07, 天天向上 <tiananlw at gmail.com> wrote:
>
> class prov(models.Model):
> prov=models.CharField("地区",maxlength=100)
> income=models.FloatField("原保险保费收入",max_digits=12, decimal_places=2)
> i_property=models.FloatField("财产险",max_digits=12, decimal_places=2)
> i_life=models.FloatField("寿险",max_digits=12, decimal_places=2)
> i_healthy=models.FloatField("健康险",max_digits=12, decimal_places=2)
> i_unexpected=models.FloatField("人身意外伤害险",max_digits=12,
> decimal_places=2)
> pub_date=models.DateField("日期")
>
>
> 我现在要实现在一段时间内的各种收入的合计,用sql 是这样的:
>
> select prov,sum(income) as income_all,sum(i_property) as
> i_property_all,.....
> from prov
> where pub_date between (begin_date,end_date)
> group by prov
>
> 请问用django的db-api怎么实现,或者能否向hibernet那样直接使用SQL语句呢?
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
--
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070726/f4b89ae7/attachment.htm
Zeuux © 2025
京ICP备05028076号