我在查询的这一部分遇到了一些问题,希望有人可以建议我,目前我将邮政编码分组为完整的邮政编码,但我想将此值拆分,并按照邮政编码的第一部分进行分组
也许我忽视了对此的简单解决方案?
这是我当前的查询
select *, count(jobline_pickup_add_postalcode) as totals
FROM rhrj_jobline
WHERE jobline_date >= '$start' AND jobline_date <= '$end'
GROUP BY jobline_pickup_add_postalcode
任何建议都很棒
编辑:
我的邮政编码看起来像这样
KA12 0RA - 1
KA15 1JG - 26
KA15 2AT - 1
KA15 2LF - 1
KA151JG/PA2 6LA - 2
答案 0 :(得分:0)
选择SUBSTRING_INDEX(jobline_pickup_add_postalcode,'',1)AS papc,count(jobline_pickup_add_postalcode)作为总计FROM rhrj_jobline WHERE jobline_date&gt; ='$ start'AND jobline_date&lt; ='$ end'GROUP BY papc