常用SQL语句

1. 查询不包含指定内容的数据

 select * from [ZY].[dbo].[l_DiseaseSymptoms] where  Disease_Name='脾肺积热' and Disease_Type NOT LIKE '%八纲辨证%'

2. 读取名字重复两次以上的数据

select Disease_Name, count(Disease_Name) from l_DiseaseSymptoms  group by Disease_Name having count(Disease_Name)>1

3. 获取栏位最长的数据(看看最长的数据有多长)

SELECT TOP 1 Item_NiShiSpeak, LEN(Item_NiShiSpeak) AS length
FROM s_BookItem
ORDER BY length DESC;

4. 统计不同条件的总数(按多个条件统计总数,case 使用)

select Device_ID,
SUM(case when Drug_Unit='' then Box_Num else 0 end) as zhi,
SUM(case when Drug_Unit='' then Box_Num else 0 end) as he from s_DrugInfo_DrugBox group by Device_ID;
posted @ 2023-10-08 09:25  apple-hu  阅读(12)  评论(0)    收藏  举报