C# 从SQL表中提取单个行值
我有一个sql表,需要从中提取某些数据。例如: 这是我的sql表的一个例子,我需要为我的应用程序提取星期一的红色,以获得一个实时互动程序。如此类推,我可能需要抽周二的红色或黄色C# 从SQL表中提取单个行值,c#,.net,sql,C#,.net,Sql,我有一个sql表,需要从中提取某些数据。例如: 这是我的sql表的一个例子,我需要为我的应用程序提取星期一的红色,以获得一个实时互动程序。如此类推,我可能需要抽周二的红色或黄色 是否有一个查询可以帮助我实现这一点 如果我没有弄错的话,这是一个基本的查询,可以满足您的需求。我假设表头是列名 获取周一的红色: select [monday] from table where [key] = 'Reds' select [tuesday] from table where [key] = 'Red
是否有一个查询可以帮助我实现这一点 如果我没有弄错的话,这是一个基本的查询,可以满足您的需求。我假设表头是列名 获取周一的红色:
select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds' //Preferred , Faster
获取周二的红色:
select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds' //Preferred , Faster
对于周一的红色:
select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds' //Preferred , Faster
对于周二的红军:
select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds' //Preferred , Faster
*根据您的评论,假设SUMMARY是您的表名。两种方法都有效
请参见此处的LIKE和=之间的区别:
请在此处尝试:
我正在寻找sql代码谢谢您的回复。我尝试了这个查询,但发现了错误。我从摘要中写入SELECT[Monday],其中[Key]=“Reds”,并得到一个错误,表示表名附近有错误。不确定我做错了什么。您使用的是哪种DBMS?Microsoft SQL Server?这很有效。非常感谢。