如何在下面的要求上写查询 [英] How to write query on below requirement

查看:57
本文介绍了如何在下面的要求上写查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建表LocationInfo



Id identity(1,1)主键int,

名称Nvarchar(50)not null,

位置Nvarchar(50)不为空,

图像Nvarchar(50)不为空,

IsValid位





我尝试了什么:



如何选择计数( id),一个图像,一个名称来自表名,其中有效= 1按位置分组?



我试过但我没有得到我认为的确切输出,所以可以请告诉我怎么写查询?

Create Table LocationInfo
(
Id identity(1,1) Primary key int,
Name Nvarchar(50) not null,
Location Nvarchar(50) not null,
Image Nvarchar(50) Not null,
IsValid Bit
)

What I have tried:

How to select count(id),one image,one name from Table Name where Is Valid=1 Group by location ?

I tried but i didnt get exact output what i think,so can u please tell me how to write query?

推荐答案

你想要什么图像? GROUP BY是关于聚合信息,而不是选择特定行。这可能有助于解释它: SQL GROUP By和列'名称'在选择列表中无效,因为......错误 [ ^ ]



你想要ID的数量,我们得到了 - 但为了得到这个数,你也无法得到单独的行信息。

可能,你正在尝试同时做两个任务 - 要做到这一点,你需要做两个SELECT语句,每个语句收集一行,然后将它们组合起来产生你想要的结果 - 但是我们不能为你做那个,因为我们不知道哪个图像和哪个名字你在寻找 - 而且(我怀疑)你都没有!
What image do you want? GROUP BY is about aggregating information, not selecting a specific row. This may help to explain it: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^]

You want a count of IDs, we get that - but to get that count, you can't get individual row information as well.
Probably, you are trying to do two tasks at the same time - and to do that, you would need to do two SELECT statements, each to collect one row, and combine them to produce the result you want - but we can't do that for you because we have no idea which image and which name you are looking for - and neither (I suspect) do you!


这篇关于如何在下面的要求上写查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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