问题描述
大家好,
我想要通过SQL查询以下内容.
我的表格如下:
类别代码类别Marksthere Scalepoint
1学者0 5
2共学1 NULL
3部分-1 0 10
现在这是类别表,其中字段
categorycode是主键
类别是varchar字段
标记的位字段始终为0或1
scalepoint是整数字段
现在我需要的是一个查询,该查询将导致类别中是否存在标记,即当marksthere字段为(1)时,缩放点不应出现在结果输出中
但是如果Markesthere列没有标记,即为(0),则在结果输出中应在其中包含比例点.
我需要一个SQL查询来选择所有字段....基于Marksthere
例如.
如果Marksthere为0
那么这些字段应该是categorycode,category,marksthere,scalepoint
但是当marksthere为1时
那么这些字段应该是categorycode,category,marksthere
请帮我解决我真正被卡住的问题.
提前谢谢..
问候,
Krunal Panchal
Hi everyone,
I want sql query for the following thing.
My table is as follows :
Categorycode Category Marksthere Scalepoint
1 scholastic 0 5
2 co-scholastic 1 NULL
3 part -1 0 10
Now here is the table of category where fields
categorycode is the primary key
category is the varchar field
marksthere is the bit field which is always 0 or 1
scalepoint is the integer field
Now what i need is a query which results if there is Marks in the category i.e when the marksthere field is (1) then the scale point should not come in the resultant output
But if the marksthere column has no marks i.e. it is (0) then in the resultant output should have the scalepoint in it.
I need a SQL query for selecting all the fields....on the basis of Marksthere
For eg.
if Marksthere is 0
then the fields should be categorycode, category,marksthere,scalepoint
but when marksthere is 1
then the fields should be categorycode,category,marksthere
Please help me out for the thing i am really stucked up..
Thanks in advance..
Regards,
Krunal Panchal
推荐答案
SELECT CategoryId, CategoryCode, MarksThere, CASE WHEN MarksThere = 0 THEN Convert(varchar,ISNULL(ScalePoint,0)) ELSE ''-'' END AS ScalePoint FROM TableName
希望对您有所帮助.
Hope it helps.
这篇关于下表的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!