SQL的如下:SELECT COUNT(*) AS COUNT, SUM(timelen) AS totlekeeptime, SUM(moneys) AS totletimefee, SUM(realmoneys) AS totlenewfee, areacode.area_name FROM phonedata INNER JOIN areacode ON LEFT(phonedata.ani, LEN(areacode.area_code)) = areacode.area_code WHERE starttime>'2005-12-27 00:00:00' and starttime<'2005-12-27 23:59:59' and endtime is not null and userid like '001136' GROUP BY areacode.area_name order by totlekeeptime oracle里该怎么办呢?
细节上我调整了下,加上了括号和百分号SELECT AREACODE.AREA_NAME,COUNT(*) AS COUNT,
SUM(TIMELEN) AS TOTLEKEEPTIME,
SUM(MONEYS) AS TOTLETIMEFEE,
SUM(REALMONEYS) AS TOTLENEWFEE,
FROM PHONEDATA INNER JOIN AREACODE ON (LEFT(PHONEDATA.ANI,LEN(AREACODE.AREA_CODE)) = AREACODE.AREA_CODE)
WHERE STARTTIME>'2005-12-27 00:00:00'
AND STARTTIME<'2005-12-27 23:59:59'
AND ENDTIME IS NOT NULL
AND USERID LIKE '001136%'
GROUP BY AREACODE.AREA_NAME
ORDER BY TOTLEKEEPTIME
/
只是不知道你没有限定哪个表的那些字段是不是只有一个表里面有,
如果不是,会报错的。
SUM(TIMELEN) AS TOTLEKEEPTIME,
SUM(MONEYS) AS TOTLETIMEFEE,
SUM(REALMONEYS) AS TOTLENEWFEE,
FROM PHONEDATA ,AREACODE
where substring(PHONEDATA.ANI,1,length(AREACODE.AREA_CODE)) = AREACODE.AREA_CODE
and to_date(STARTTIME,'yyyy-mm-dd hr24:mi:ss')>'2005-12-27 00:00:00'
AND to_date(STARTTIME,'yyyy-mm-dd hr24:mi:ss')<'2005-12-27 23:59:59'
AND ENDTIME IS NOT NULL
AND USERID LIKE '001136%'
GROUP BY AREACODE.AREA_NAME
ORDER BY TOTLEKEEPTIME
2.oracle里没有LEFT函数,取字接数是用length ab5669(王长林)的:两表连接那错了,但这地方: substring(PHONEDATA.ANI,1,length(AREACODE.AREA_CODE)) = AREACODE.AREA_CODE是对的我现在用:
SELECT COUNT(*) AS COUNT, SUM(timelen) AS totlekeeptime, SUM(moneys) AS totletimefee, SUM(realmoneys) AS totlenewfee, areacode.area_name FROM phonedata LEFT OUTER JOIN areacode ON (substr(phonedata.ani,0,length(areacode.area_code)) = areacode.area_code) WHERE starttime>'2005-12-27 00:00:00' and starttime<'2005-12-27 23:59:59' and endtime is not null and userid like '001136' GROUP BY areacode.area_name order by totlekeeptime
可以查到数据了并且也统计了现在的问题变成了area_name的值不显示,其他值都有
SUM(realmoneys) AS totlenewfee, areacode.area_name
FROM phonedata ,areacode
WHERE starttime>'2005-12-27 00:00:00' and starttime<'2005-12-27 23:59:59'
and endtime is not null and userid like '001136'
/*and LEFT(phonedata.ani, length(areacode.area_code)) = areacode.area_code */
and substr(phonedata.ani, 1,length(areacode.area_code)) = areacode.area_code
GROUP BY areacode.area_name order by totlekeeptime看看行不行,inner join 直接相等就可以了,left换成substr
SELECT COUNT(*) AS COUNT, SUM(timelen) AS totlekeeptime, SUM(moneys) AS totletimefee, SUM(realmoneys) AS totlenewfee, areacode.area_name FROM phonedata LEFT OUTER JOIN areacode ON (substr(phonedata.ani,0,length(areacode.area_code)) = areacode.area_code) WHERE starttime>'2005-12-27 00:00:00' and starttime<'2005-12-27 23:59:59' and endtime is not null and userid like '001136' GROUP BY areacode.area_name order by totlekeeptime
可以查到数据了并且也统计了可area_name的值不显示,其他值都有,十分不解!!
将上面的0改为1看看.