1.普通查询
select * from [TName]
查询表【TName】表的所有数据和字段
select Name from [TName]
查询当前表指定的字段
select distinct Tel from [YP_Store]
查询某列不相同的数据distinct
select distinct Tel ,Name from [YP_Store] where CreatonTime >= '2021-04-12 00:00:00'
查询时间的比较
select distinct Tel ,Id from [YP_Store] order by Id
排序Id
select distinct Tel ,Id from [YP_Store] order by Id desc
相反顺序倒序desc、正序Asc
2.Top获取前几个数据
SELECT TOP 2 * FROM Persons
3. like 查找相似的字段数据
SQL 通配符
4. in 和where使用表示在某个字段中筛选想要的字段值
select * from [YP_Store] where Name in('Name')
5.between 查询条件介于什么范围之间
select * from [YP_Store] where Name between '' and '111'
----
6.linq 连表查询
var query1 = from x in context.YP_Store where x.Id == 2 select new { x.Name, x.Id };
var query2 = from x in context.YP_Account select new { x.Id,x.Name,x.StoreId};
var query3 = from t1 in query1 join t2 in query2 on t1.Id equals t2.StoreId select new { SN=t1.Name,AN=t2.Name};
var data = query3.ToList();
var query4 = from t1 in from x in context.YP_Store where x.Id == 2 select new { x.Name, x.Id } join t2 in from x in context.YP_Account select new { x.Id, x.Name, x.StoreId } on t1.Id equals t2.StoreId select new { SN = t1.Name, AN = t2.Name };
var data2 = query3.ToList();
data等于data2;
7.linq 分组查询
var query1 = (from x in _IMembersMoneyPayItemRecordService.GetAll()
where x.CreatonTime >= BeginTime && x.IsDeleted == false
group x by x.PayType into g
select new { ActualChange = g.Sum(y => y.ActualChange), PayType = g.Key }).ToList();
---------------
8.sql跨表更新字段
UPDATE `v3城市对应经纬度`, city_info
SET city_info.latitude = `v3城市对应经纬度`.latitude,city_info.longitude = `v3城市对应经纬度`.longitude
WHERE `v3城市对应经纬度`.CtiyId = city_info.cityCode
9.sql更新某个表的字段
-- 更新某个字段
UPDATE device_item
SET supplier="linglu"
WHERE supplier IS NULL