具有附加条件的 MySQL GROUP BY
我目前正在使用此 MySQL 语句:
SELECT * FROM jobs GROUP BY jobType, address1;
我需要能够向此查询添加另一个条件。 GROUP BY 仅合并重复项,但我还需要合并 jobType 为“1”或 jobType 为“2”的所有行。所有其他 jobTypes 将正常分组。
例如,我的表看起来像这样:
jobType | address1
1 | 123 State st
2 | 123 State st
3 | 415 5th Ave
1 | 123 State st
1 | 24 3rd Ave
1 | 123 State st
3 | 555 Mission st
4 | 123 State st
我想合并第 1 行和第 2 行,即使它们的 jobType 不同。同样,任何 jobType 不是 1 或 2 的行都会被正常分组。
I'm currently working with this MySQL statement:
SELECT * FROM jobs GROUP BY jobType, address1;
I need to be able to add another condition to this query. GROUP BY only combines duplicates, but I also need to combine all rows that have a jobType of '1' or a jobType of '2'. All other jobTypes will be grouped normally.
For example, my table looks something like this:
jobType | address1
1 | 123 State st
2 | 123 State st
3 | 415 5th Ave
1 | 123 State st
1 | 24 3rd Ave
1 | 123 State st
3 | 555 Mission st
4 | 123 State st
I want to combine rows 1 and 2, even though their jobType is different. Again, any rows with a jobType other than either 1 or 2 would be grouped normally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)