select l.busi_sid,t.hfbh,l.subtype, subtype1,l.logtype,t.jbdwmc,t.hfnr,t.hfsj,t.hfr,t.ywbh,t.sid$
from t_jc_ms_busi_log l, t_jc_ms_hfb t where l.busi_sid = t.sid$
group by l.busi_sid, substr(l.subtype, 0, 2),l.logtype,t.hfbh,t.jbdwmc,t.hfnr,t.hfsj,t.hfr,t.ywbh,t.sid$
我想排序的时候截取l.subtype字段的前面2个排。。怎么这么写不行呢。?
各位高手 指点下···
一个逗号写成中文标点
查询字段有两个没有聚合:l.subtype, subtype1,
修改下
如果不需要统计,只要去重复
select distinct l.busi_sid,t.hfbh,substr(l.subtype, 0, 2),l.logtype,t.jbdwmc,t.hfnr,t.hfsj,t.hfr,t.ywbh,t.sid$
from t_jc_ms_busi_log l, t_jc_ms_hfb t where l.busi_sid = t.sid$
这样应该就可以了
Order by substr(l.subtype, 0, 2)
这样改,分组的那块没了?
我想查l.subtype这个字段的时候还是显示完整的,只是group by就按l.subtype前2位的。
必须聚合,要不会出错
select distinct l.busi_sid,t.hfbh, l.subtype, subtype,l.logtype,t.jbdwmc,t.hfnr,t.hfsj,t.hfr,t.ywbh,t.sid$,
sum(case when curstatustype='1' then 1 else 0 end ) yj,
sum(case when curstatustype='2' then 1 else 0 end ) yyj,
sum(case when curstatustype='5' then 1 else 0 end ) ryj,sum(case when curstatustype='8' then 1 else 0 end ) yp,
sum(case when curstatustype='11' then 1 else 0 end ) rp,max(curstatustype) as curstatustype
from t_jc_ms_busi_log l, t_jc_ms_hfb t where l.busi_sid = t.sid$ and l.subtype like '21%%'
and t.hfbh like '%%'
and t.hfr like '%%'
group by l.busi_sid,substr(l.subtype, 0, 2),l.logtype,t.hfbh,t.jbdwmc,t.hfnr,t.hfsj,t.hfr,t.ywbh,t.sid$
完整的是这样,查的l.subtype字段显示完整,分组的时候是按其前2位
我不明白,subtype前两位相同的,后面几位不相同吧,要不你也不会根据前两位分组
比如subtype字段是这样的
subtype
12345
12445
13431那么根据前两位分组会分成2组,原表3条记录如何显示在两条结果里?
12(?)
13..
T.HFBH,
L.SUBTYPE,
SUBSTR(L.SUBTYPE, 0, 2),
SUBTYPE,
L.LOGTYPE,
T.JBDWMC,
T.HFNR,
T.HFSJ,
T.HFR,
T.YWBH,
T.SID$,
SUM(DEOCDE(CURSTATUSTYPE, '1', 1, 0)) YJ,
SUM(DEOCDE(CURSTATUSTYPE, '2', 1, 0)) YYJ,
SUM(DEOCDE(CURSTATUSTYPE, '5', 1, 0)) RYJ,
SUM(DEOCDE(CURSTATUSTYPE, '8', 1, 0)) YP,
SUM(DEOCDE(CURSTATUSTYPE, '11', 1, 0)) RP,
MAX(CURSTATUSTYPE) AS CURSTATUSTYPE
FROM T_JC_MS_BUSI_LOG L, T_JC_MS_HFB T
WHERE L.BUSI_SID = T.SID$
AND L.SUBTYPE LIKE '21%%'
AND T.HFBH LIKE '%%'
AND T.HFR LIKE '%%'
GROUP BY L.BUSI_SID,
T.HFBH,
L.SUBTYPE,
SUBSTR(L.SUBTYPE, 0, 2),
SUBTYPE,
L.LOGTYPE,
T.JBDWMC,
T.HFNR,
T.HFSJ,
T.HFR,
T.YWBH,
T.SID$
不知道是不是你要的效果。
另外distinct 就不需要 GROUP BY 了吧。
from t_jc_ms_busi_log l, t_jc_ms_hfb t where l.busi_sid = t.sid$
group by l.busi_sid, substr(l.subtype, 0, 2),l.logtype,t.hfbh,t.jbdwmc,t.hfnr,t.hfsj,t.hfr,t.ywbh,t.sid$应该这样就可以了,我以前有试过,在分组条件没有的列要用聚合函数才行,楼主试试
但是,解决了语法问题之外
7楼的增加了一个分组字段,可这使得分组没有意义了
和我在1楼改的其实是一个意思
10楼的,subtype前两位相同的情况下取l.subtype的最大值,这是楼主想要的结果吗
不知道楼主想要什么,所以很困惑