【发布时间】:2017-10-19 22:58:05
【问题描述】:
假设我在表 resume_profiles 中有 2 列
current_location city
| Chennai | | Kolkatta |
| Mumbai | | Ahmaedabad |
| Pune | | Kolkatta |
| Kolkatta | | Pune |
我需要将这些结果组合成一个 SET,所以我有这样的东西:
City Aggregate
| Chennai | | 1 |
| Mumbai | | 1 |
| Pune | | 2 |
| Kolkatta | | 3 |
| Ahmaedabad | | 1 |
查询:
$current_locations = ResumeProfile::selectRaw('current_location as city');
ResumeProfile::selectRaw('city,count(*) as aggregate')
->unionAll($current_locations)
->groupBy('city')->get();
当我使用上述查询时,我得到以下查询,但有异常
SQLSTATE[21000]:基数违规:1222 使用的 SELECT 语句具有不同的列数(SQL: (select city,count(*) as aggregate from resume_profiles group by city) union all (从resume_profiles中选择current_location作为城市))
我不知道如何实现这一点
【问题讨论】: