我想对code这一列做分组统计,请问大神sql语句该怎么写?
这是我写的sql语句
SELECT
t1.id,
t1.code,
t1.[count],
dbo.dictText (t1.dwmc, 'dwmc') AS dwmc,
dbo.dictText (t1. LEVEL, 'tar_level0') AS LEVEL,
dbo.dictText (t1.wd_id, 'wd_detail') AS wd_id,
dbo.dictText (t1.bd_id, 'bd_detail') AS bd_id,
dbo.dictText (t1.property, 'tar_property') AS property,
dbo.dictText (t1.data_from,'tar_datafrom') AS data_from,
t1.create_time,
t1.repeal_time
FROM
tar_rentou t1
INNER JOIN activity t2 ON t2.target_code = t1.code
执行后的sql语句如下图
经过不懈的努力终于写出了sql语句
SELECT
dbo.dictText (dwmc, 'dwmc') AS dwmc,
code,
COUNT (1) AS mbcount,
dbo.dictText (LEVEL, 'tar_level0') AS LEVEL,
dbo.dictText (wd_id, 'wd_detail') AS wd_id,
dbo.dictText (bd_id, 'bd_detail') AS bd_id,
dbo.dictText (property, 'tar_property') AS property,
dbo.dictText (data_from, 'tar_datafrom') AS data_from,
create_time,
repeal_time
FROM
(
SELECT
code,
dwmc,
[level],
wd_id,
bd_id,
property,
data_from,
create_time,
repeal_time
FROM
tar_rentou
INNER JOIN activity t2 ON t2.target_code = tar_rentou.code
) _t
GROUP BY
code,
dwmc,
LEVEL,
wd_id,
bd_id,
property,
data_from,
create_time,
repeal_time
执行后的sql语句如下图
很开心功夫不负有心人