MySQL SELECT 语句问题
我有以下查询,它返回 2 个元组。
SELECT bar_id, bar_name, town_name, bar_telephone, subscription_type_id, pic_type
FROM towns, subscriptiontype, regions, bar
LEFT JOIN barpictures bp ON bar.bar_id = bp.bar_id_fk
WHERE town_id = town_id_fk
AND bar.test_field = 0
AND subscription_type_id = subscription_type_id_fk
AND region_id = region_id_fk
AND (type like 'logo%' OR type IS NULL)
元组之间的主要区别在于,一个元组具有“type”= logo,另一个元组具有“type”= logo_large。我需要的不是两个元组,而是两个类型属性,一个包含“logo”,另一个包含“logo_large”,
例如
bar_id, bar_name, town_name, bar_telephone, subscription_type_id, pic_type1, pic_type2
这可能吗?
I have the following query which returns 2 tuples
SELECT bar_id, bar_name, town_name, bar_telephone, subscription_type_id, pic_type
FROM towns, subscriptiontype, regions, bar
LEFT JOIN barpictures bp ON bar.bar_id = bp.bar_id_fk
WHERE town_id = town_id_fk
AND bar.test_field = 0
AND subscription_type_id = subscription_type_id_fk
AND region_id = region_id_fk
AND (type like 'logo%' OR type IS NULL)
The main difference between the tuples is that one has 'type' = logo and the other tuple has 'type' = logo_large. I need that instead of having two tuples, I need that I have 2 type attributes, one holding the "logo" and the other the "logo_large"
eg
bar_id, bar_name, town_name, bar_telephone, subscription_type_id, pic_type1, pic_type2
is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的:
想法是使用聚合函数来合并行并仅选择与您的条件匹配的值(对于不匹配的行,聚合函数应返回 null)
Yes, it is possible:
The idea is to use aggregating functions to merge the rows and select only the value that matches your condition (for non-matching rows the aggregating function should return null)