select sysid,
case when Type='1' then '水表' end Type1,
case when Type='5' then '电表' end Type5,
case when Type='1' then cbjlb_syds end syds1,
case when Type='5' then cbjlb_syds end syds5
from tb1 a,tb2 b Where
a.sysid=b.sysidsysid type1 type5 syds1 syds5
SB00000080 水表 NULL 6.00 NULL
SB00000080 NULL 电表 NULL 11.00怎么把上面的语句改一下 效果是sysid type1 type5 syds1 syds5
SB00000080 水表 电表 6.00 11.00
case when Type='1' then '水表' end Type1,
case when Type='5' then '电表' end Type5,
case when Type='1' then cbjlb_syds end syds1,
case when Type='5' then cbjlb_syds end syds5
from tb1 a,tb2 b Where
a.sysid=b.sysidsysid type1 type5 syds1 syds5
SB00000080 水表 NULL 6.00 NULL
SB00000080 NULL 电表 NULL 11.00怎么把上面的语句改一下 效果是sysid type1 type5 syds1 syds5
SB00000080 水表 电表 6.00 11.00
select
a.sysid,
max(case when Type='1' then '水表' end) Type1,
max(case when Type='5' then '电表' end) Type5,
max(case when Type='1' then cbjlb_syds end) syds1,
max(case when Type='5' then cbjlb_syds end) syds5
from
tb1 a,tb2 b
Where
a.sysid=b.sysid
group by
a.sysid
a.sysid,
MAX(CASE WHEN type='1' then '水表' end) type1,
MAX(CASE WHEN type='5' THEN '电表' END) type5,
MAX(CASE WHEN type='1' THEN cbjlb_syds END) syds1,
MAX(CASE WHEN type='5' THEN cbjlb_syds END)syds5
FROM tb1 a
INNON JOIN tb2 b
ON a.sysid=b.sysid
GROUP BY a.sysid
select
a.sysid,
max(case when Type='1' then '水表' end) Type1,
max(case when Type='5' then '电表' end) Type5,
max(case when Type='1' then cbjlb_syds end) syds1,
max(case when Type='5' then cbjlb_syds end) syds5
from tb1 a,tb2 b Where
a.sysid=b.sysid
group by a.sysid
a.sysid,
max(case when Type='1' then '水表' end) Type1,
max(case when Type='5' then '电表' end) Type5,
max(case when Type='1' then cbjlb_syds end) syds1,
max(case when Type='5' then cbjlb_syds end) syds5
from tb1 a,tb2 b Where
a.sysid=b.sysid
group by a.sysid