从表中选择值,但值应显示在C,S,A字符串中 [英] Select value from table but value should be display from C,S,A string

查看:49
本文介绍了从表中选择值,但值应显示在C,S,A字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我面临的一个问题是,,,

在一个表中,响应,存在状态属性,,,



状态

确认

应用

短名单

短名单

确认





我想输出应该显示如下...

确认

确认

ShortList

ShortList

应用

hello I am facing one problem which is,,,
In one table Response, which exist status attribute,,,

Status
Confirm
Applied
ShortList
ShortList
Confirm


I want output should be display like this...
Confirm
Confirm
ShortList
ShortList
Applied

推荐答案

听起来像糟糕的设计,正如我在评论中写到你的问题...



临时你可以帮助自己添加带有列的表来处理排序顺序。



Sounds like bad design, as i wrote in comments to your question...

Temporary you can help yourself adding table with column to handle sort order.

--table to handle sort order
DECLARE @statuses TABLE([Status] VARCHAR(30), [SortOrder] INT)

INSERT INTO @statuses ([Status], [SortOrder])
VALUES('ShortList', 2)
INSERT INTO @statuses ([Status], [SortOrder])
VALUES('Applied', 3)
INSERT INTO @statuses ([Status], [SortOrder])
VALUES('Confirm', 1)

--table with statuses
DECLARE @tbl TABLE([Status] VARCHAR(30))

INSERT INTO @tbl ([Status])
VALUES('ShortList')
INSERT INTO @tbl ([Status])
VALUES('Confirm')
INSERT INTO @tbl ([Status])
VALUES('ShortList')
INSERT INTO @tbl ([Status])
VALUES('Applied')
INSERT INTO @tbl ([Status])
VALUES('ShortList')
INSERT INTO @tbl ([Status])
VALUES('Applied')
INSERT INTO @tbl ([Status])
VALUES('ShortList')
INSERT INTO @tbl ([Status])
VALUES('Confirm')

SELECT t1.[Status], t2.[SortOrder]
FROM @tbl AS t1 INNER JOIN (SELECT * FROM @statuses) AS t2 ON t1.[Status] = t2.[Status]
ORDER BY [SortOrder]





结果C ,S,A订单:



Result in C,S,A order:

[Status]    [SortOrder]
Confirm     1
Confirm     1
ShortList   2
ShortList   2
ShortList   2
ShortList   2
Applied     3
Applied     3


这篇关于从表中选择值,但值应显示在C,S,A字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆