简体   繁体   English

在Webform标签中的SQL数据库中显示满足2个条件的项目

[英]Displaying an item that meets 2 conditions in a SQL database in a Webform label

在此处输入图片说明 I'm completely new to SQL, so please bear with me. 我对SQL完全陌生,所以请耐心等待。

I'm basically trying to display an item that meets 2 conditions within an SQL database in a Webform on Visual Studio using C#. 我基本上是在尝试使用C#在Visual Studio上的Webform中的SQL数据库中显示满足2个条件的项目。

The table consists of words according to category and level(easy, medium, hard). 该表根据类别和级别(容易,中等,困难)由单词组成。 The webform allows the user to select multiple categories using check boxes and the level via a drop down list. 该网络表单允许用户使用复选框选择多个类别,并通过下拉列表选择级别。

I would like to display a single word within the database depending on which level and which category has been chosen. 我想根据选择的级别和类别在数据库中显示一个单词。

I've attached a picture of what the table looks like. 我已附上一张桌子的图片。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thank you 谢谢 在此处输入图片说明

Most of the reason you were struggling with a query here is because the data model is less than optimal. 您在此处努力查询的大多数原因是因为数据模型不够理想。 Here is better model for your words. 这是您的最佳选择。

create table Words
(
    LevelID int
    , CategoryID int
    , Word varchar(50)
)

create table WordLevel
(
    LevelID int
    , LevelDescription varchar(25)
)

create table Category
(
    CategoryID int
    , CategoryDescription varchar(50)
)

insert WordLevel
select 1, 'Easy' union all
select 2, 'Medium' union all
select 3, 'Hard'

insert Category
select 1, 'flora' union all
select 2, 'space' union all
select 3, 'wildlife'

insert Words
select 1, 1, 'sunflower' union all
select 1, 2, 'pluto' union all
select 1, 3, 'lion'

select * --of course you would only include the columns you actually need here
from Words w
join Category c on c.CategoryID = w.CategoryID
join WordLevel wl on wl.LevelID = w.LevelID
where w.LevelID = 1
    and c.CategoryDescription = 'space'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM