佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1734|回复: 1

会sql的进来

[复制链接]
发表于 4-3-2009 07:04 AM | 显示全部楼层 |阅读模式
1.
Aggregate the calls bythe telephone number they were made from, presenting the total number of phonecalls, total number of minutes, and the total charge.

2.
Based on the above,show the top 5 callers with respect to the total number of minutes.

3.
Show the total numberof calls made to normal telephone numbers (callsNormNumbers), the total numberof calls made to special-service numbers (callsSpecNumbers) and theirdifference (callsOrdNumbers - callsSpecNumbers), per month.

谁可以帮我写以上的SQL Expressions??



[ 本帖最后由 Siangboy 于 12-3-2009 09:15 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 17-4-2009 09:48 AM | 显示全部楼层
自己回答自己

1
SELECT FROMTELNO AS "TEL NO.", COUNT(*) AS "TOTAL NO. OF CALLS",
  ROUND(SUM(endtime - starttime),4) * 24 * 60 AS "NO. OF MINUTES",
  SUM(charge) AS "TOTAL CHARGE"
FROM telco_calls
GROUP BY fromtelno;

2
SELECT * FROM
(SELECT FROMTELNO AS "FROM TEL NO" , ROUND(SUM(endtime - starttime),4) * 24 * 60 AS "NO. OF MINUTES"
  FROM telco_calls
  GROUP BY fromtelno
  ORDER BY "NO. OF MINUTES" DESC)
WHERE ROWNUM <= 5;

3
SELECT "Month" AS "MONTH", callsNormNumbers AS "CALLS TO NORMAL NUMBER", callsSpecNumbers AS "CALLS TO SPECIAL NUMBER", callsNormNumbers - callsSpecNumbers AS "CALLS DIFFERENCE"
FROM
(SELECT to_char(starttime, 'MON') AS "Month", COUNT(TOAC) AS callsNormNumbers
FROM telco_calls
WHERE NOT(TOAC = 0870 OR TOAC = 0844 OR TOAC = 0900)
GROUP BY to_char(starttime, 'MON')),

(SELECT to_char(starttime, 'MON') AS month2, COUNT(TOAC) AS callsSpecNumbers
FROM telco_calls
WHERE TOAC = 0870 OR TOAC = 0844 OR TOAC = 0900
GROUP BY to_char(starttime, 'MON'))

WHERE "Month" = month2
ORDER BY "Month";
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 15-12-2025 03:57 AM , Processed in 0.142200 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表