分类: Sql语句
sql查询使用inner join出现重复数据问题
inner join 的表会把该表符合on条件的数据全部列出来与前面的表、inner join表数据形成多余的数据例如:select * from table1 t1inner join table2 t2 on t2.col1 = t1.col1 and t2.col2=t2.col2where t1. col3=’x’ 结果会出现单独查询 select * from table1 where col3=’x’ 只有1条记录但是因为table2存在100条 t2.col2=t1.col2 and t2.col1=t1.col1 导致上面的inner join语句执行完会出现100条记录
详细内容SqlSugar的GetList时提示Operand should contain 1 column(s)
给魔码挪车小程序写webapi某个功能时,写了如下代码: return base.GetList(it=>ids.Length>0 && SqlFunc.ContainArray(ids,it.Id)) 报错:Operand should contain 1 column(s) 经百度,提示是in子查询时出现了2个字段(in (select id,true from [xxx] where ….)) 所以上面修改为: return base.GetList(it=> SqlFunc.ContainArray(ids,it.Id)) 问题解决
详细内容select count的统计某字段数据分别重复次数语句
表 A id name city 1 李先生 福州 2 王先生 厦门 3 张三 广州 4 李四 厦门 5 王五 福州 6 赵六 厦门 如果要统计厦门有几个人,福州有几个人,可以使用如下语句: select count(*) as c,city from [a] group by city order by c desc 可以得到如下结果 c city 3 厦门 2 福州 1 广州
详细内容