SQL语句

1.获取不同设备的最后一条记录 SQL消费表中查找所有用户最后一条消费记录

 select a.* from GPRS.DBO.View_GPRS

a where not exists(select 1 from GPRS.DBO.View_GPRS where 设备号 = a.设备号 and 采集时间 > a.采集时间 )

优化:

select a.* from [TYN].[dbo].[View_SolarEnergy] a
where not exists(select 1 from [TYN].[dbo].[View_SolarEnergy] b
where b.设备编号 = a.设备编号 and b.数据采集时间 > a.数据采集时间)

 

 

2.获取当天时间最新的20条数据,并且各个字段值都不为空

string cmd = "select TOP 20 温度,电池电压,电池电量,采集时间 from View_GPRS where 温度 is not null and 电池电压 is not null and 电池电量 is not null and 采集时间>'" + currentDateTime + "' and 设备号 ='" + IMEI + "' order by 采集时间 desc";

select TOP 20 温度,电池电压,电池电量,采集时间 from GPRS.dbo.View_GPRS
where 温度 is not null and 电池电压 is not null and 电池电量 is not null and 采集时间>'2019/10/17' and 设备号 ='868221048182987' order by 采集时间 desc

 

posted @   Youse的二分口粮地  阅读(201)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
点击右上角即可分享
微信分享提示