gpt4 book ai didi

mysql - SQL 查询从数据表中选择不同的值以及相应的列值

转载 作者:行者123 更新时间:2023-11-29 10:07:16 25 4
gpt4 key购买 nike

我有一个数据表,其中包含 4 个字段 [UpdatedDate][DoggoName][DoggoType] [DoggoAge]

[DoggoName] 将始终具有相同的 [DoggoType][DoggoAge] 值。

UpdatedDate DoggoName   DoggoType        DoggoAge
1-Jan a Labrador 1
1-Jan b Yorkshire 2
1-Jan c German Shepherd 3
1-Jan e Bull Terrier 2
2-Jan a Labrador 1
2-Jan d Golden Retriever 1
2-Jan e Bull Terrier 2
2-Jan f Poodle 3
3-Jan a Labrador 1
3-Jan b Yorkshire 2
3-Jan c German Shepherd 3

我希望在 2 个 [UpdatedDate] 及其相应的 [DoggoType] 和“[DoggoAge] 之间选择不同的 [DoggoName]” `.

到目前为止,我只设法提出一个基本的 SQL 查询来提取不同的 [DoggoName]。在 Excel 上打印,然后循环遍历 [DoggoName] 的行以绘制其他 2 列。我想知道是否有一个查询可以跳过我繁琐的循环。

我的 SQL 查询:

SELECT DISTINCT [DoggoName] 
FROM [DataTable]
WHERE [UpdatedDate] BETWEEN #1-Jan-2018# AND #2-Jan-2018#

我的最终输出应如下所示:

DoggoName   DoggoType        DoggoAge
a Labrador 1
b Yorkshire 2
c German Shepherd 3
e Bull Terrier 2
d Golden Retriever 1
f Poodle 3

最佳答案

您可以使用DISTINCT选择您的期望列。

SELECT DISTINCT DoggoName,DoggoName,DoggoAge
FROM DataTable

关于mysql - SQL 查询从数据表中选择不同的值以及相应的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51704956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com