添加两个不同的ID我有两个表
第一个名字screen_main有场
screen_main_id,screen_date,start_date,end_date
1 12 15
2 13 15
3 14 16
我有两个起点之间取一个screen_main_id日期和结束日期后,我有另一个表名screen_product表
field:
screen_id screen_main_id article_id quantity price %age
1 1 1 5 234 12%
2 2 1 6 221 12%
3 1 2 5 111 10%
现在第一张桌子给我screen_main_id当我选择开始日期和结束日期后选择screen_main_id我必须总结所有的数据具有artical组明智的就像artical = 1那么它做的总和我们得到的两个id从第一张桌子。
我的回答
用于选择第一screen_main_id
select * from screen_main where screen_date between start_date='$start_date' and end_date='$end_date'
取得被screen_main_id
select sum(quantity) ,sum(price),sum(%age) from screen_product where screen_main_id='$screen_main_id' group by aitical_id
它添加,但如果在screen_main_id变化则分为两个部分它不给休息后us sum
如果有任何问题,请帮助我EM了解请我的问题问我 感谢
等待,第一个表中的列的值是什么?你显示四个名字,但只有三列的数据 – dldnh 2012-03-22 15:41:22
我正在使用screen_data当我在start_date和end_date之间获取日期那个时候我正在使用这个字段 – 2012-03-22 18:57:29