Sql 我一排只想要一个国家?
我一排只想要一个国家 我加入了两列Sql 我一排只想要一个国家?,sql,sql-server,Sql,Sql Server,我一排只想要一个国家 我加入了两列 SELECT brief_title AS Title, study_type AS [Study Type], location_countries_country + location_facility_address_country AS Country, FROM [dbo].[ClinicalTrialStaging] WHERE study_type = 'all' AND (locati
SELECT
brief_title AS Title,
study_type AS [Study Type],
location_countries_country + location_facility_address_country AS Country,
FROM
[dbo].[ClinicalTrialStaging]
WHERE
study_type = 'all'
AND (location_countries_country LIKE '%United States%' OR
location_facility_address_country LIKE '%United States%')
我得到了这个结果:
Country
----------------------------
United States|United States|
United States|United States|
United States|United States|
同一排我有两个国家,但我只希望某一排有一个国家我想你要找的是
GROUP BY country
例如:
location_countries_country + location_facility_address_country AS Country
from customer
WHERE (location_countries_country like '%United States%' or
location_facility_address_country like '%United States%')
GROUP BY Country
编辑您的帖子将代码放在一个片段上更容易阅读=/另外,请详细说明一下表格。实际上在大多数SQL方言中,
GROUP BY
必须在WHERE
子句之后…我的错,只是忘了将其更改为HAVING,但HAVING应仅应用于聚合列-例如,如果使用SUM
或COUNT
-则不适用于“正常”条件,如之类的。。。。。