SQL列/行格式问题
我的查询返回一个可以保存房地产类型的列。值可以是condo或duplex或house等。我只想在列中显示一个 C,而不是显示公寓。我的计划是使用一个巨大的 case/when 结构来覆盖所有的情况,有没有更简单的方法?顺便说一句,仅以大写形式显示第一个字母是行不通的,因为有时无法应用该规则来创建短代码。例如,双工是DE...
谢谢:-)
my query returns a column that can hold types of real estate. Values can be condo or duplex or house and so on. Instead of displaying condo, I just want a C in the column. My plan was to use a huge case/when structure to cover all the cases, is there an easier way? Just displaying the first letter in upper case wont work by the way, because sometimes that rule cant be applied to create the short code. Duplex for example is DE...
Thanks :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您不想使用 CASE 语句,如何创建一个查找表来将列值映射到您想要的查找代码。在您的查询中加入这一点。
注意 - 仅当您的查询运行在相当小的结果集上时才值得考虑,否则您会遇到性能问题。为该列建立索引会有所帮助。
其他一些选项取决于您的数据库服务器功能:
If you don't want to use a CASE statement how about creating a lookup table to map the column value to the lookup code you want. Join on to this in your query.
NB - Only worth considering if your query is running over a fairly small resultset or you'll hit performance issues. Indexing the column would help.
Some other options are depending on your DB server features:
辅助表中每个与长字符串匹配的速记都有一列?
Helper table with a column for each shorthand matching the long string?
显而易见的做法是创建另一个表,将您的值映射到代码,然后您可以将结果连接到该代码。但闻起来有点不对劲。我想将另一个表连接到键值,而不是字符串(我认为不是键值)
The obvious thing to do would be to have another table which maps your value to a code, to which you can then join your results. But it smells a bit wrong. I'd want to join this other table to key values, not strings (which I assume aren't key values)
为什么不在sql中使用 decode 函数
Why dont you use a decode function in sql