以下是表格//感谢您修复我的格式//
ADV_COST
--------
PAGE_SIZE
MAG_ID
COST
//SAMPLE DATA ADV_COST//
PAGE_SIZE MAG_ID COST
-------------------- ---------- ----------
1/25 PAGE 1 40
1/8 PAGE 1 60
1/6 PAGE 1 65
...
ADS
--------
AD_ID
ADV_ID
PAGE_SIZE
MAG_ID
START_DATE
PURCH_DATE
NUM_ISSUES
//SAMPLE DATA ADS//
AD_ID ADV_ID PAGE_SIZE MAG_ID START_DAT PURCH_DAT NUM_ISSUES
---------- ---------- ---------- ---------- --------- --------- ----------
1 5 1/4 PAGE 1 01-APR-11 01-MAR-11 4
...
这是一个问题:
惠而浦ADV_ID = 6;房屋:MAG_ID = 1;
“惠而浦本月在房屋广告上花了多少钱?今年?”
请帮助,谢谢!这就是我尝试过的。
SQL> SELECT SUM(COST)
2 FROM DVD_ADV_COST A, DVD_ADS B
3 WHERE A.MAG_ID = B.MAG_ID
4 AND B.ADV_ID = 6
5 AND B.MAG_ID = 1;
答案 0 :(得分:0)
尝试
SELECT SUM(B.COST * A.NUM_ISSUES) AS TOTAL_COST
FROM DVD_ADS A,
DVD_ADV_COST B
WHERE B.MAG_ID = A.MAG_ID
AND B.PAGE_SIZE = A.PAGE_SIZE
AND A.ADV_ID = 6
AND A.MAG_ID = 1
然后将您的日期范围添加到WHERE子句
如果它没有返回任何数据,请确保您实际上有ADV_ID = 6的条目....您的示例显示5的条目