SQL 列合并和聚合函数
我有一个简单的表,有两列(两列感兴趣,加上一个ID)...我有一个ajax搜索,它只是寻找关键字...然后将其发送到我真正的搜索...ajax搜索不关心它们是什么,但它们需要不同...
我怎样才能将两列合并在一起:
City, Country
Krakow, Poland
Warsaw, Poland
Austin, USA
New York, USA
Prague, Czech Republic
这样我就可以
Keyword, Sideinfo
Krakow, Poland
Warsaw, Poland
Austin, USA
Prague, Czech Republic
USA, Country (only once)
Poland, Country
Czech Republic, Country
尝试做一个 UNION 但我不确定如何做一个 WHERE LIKE 'keyword%'
希望这是有道理的......
I have a simple table with two columns (well two columns of interest, plus just an ID)... I have an ajax search which is just looking for keywords... which are then sent to my real search... the ajax search doesn't care what they are, but they need to be distinct...
How can I merge the two columns together:
City, Country
Krakow, Poland
Warsaw, Poland
Austin, USA
New York, USA
Prague, Czech Republic
So that I would get
Keyword, Sideinfo
Krakow, Poland
Warsaw, Poland
Austin, USA
Prague, Czech Republic
USA, Country (only once)
Poland, Country
Czech Republic, Country
I tried doing a UNION but I'm not sure how i'd do a WHERE LIKE 'keyword%'
Hope that makes sense...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个。
Try this.
这应该可以做到:
This should do it: