如下表: 表名:Test ID RowID Col1 Col2 1 1 A A 2 1 B A 3 1 A B 4 1 C B 1,查找表中字段重复的只查找一次 select distinct Col1 from Test ; select Col1 from Test where ID in(select min(ID) from Test group by Col1 ); 结果为: A B C 2,统计并查询该字段出现的数量 SELECT Col1,COUNT(Col1) FROM Tes…
1,把表中某一列的内容合并为一行 select province,CONCAT('[\"全部\",\"',GROUP_CONCAT(city ORDER BY cityID separator '\"\,\"'),'\"]') as group1 from hat_city a LEFT JOIN hat_province b on a.father=b. provinceID GROUP BY father ORDER BY cityID:根据…
select ID, Name = ( stuff ( ( select ',' + Name from Table_1 where ID = a.ID for xml path('') ),1,1,'' ) ) from Table_1 a group by ID 原始数据: ID Name A S A M A L B S B M B L 结果数据: ID NameA S,M,LB S,M,L…
select '['+title_a+','+title_b +']' from A for xml path('') SELECT *, (select '['+title_a+','+title_b +']' from A where A.t_id=B.t_id for xml path('')) FROM B…
li = []with open('lo', encoding='utf-8', mode='r') as f1: for i in f1: l2=i.strip().split() dic = {'name':l2[0], 'price':l2[1], 'amount':l2[2]} li.append(dic)print(li)sum = 0for j in li: sum=sum+int(j['price'])*int(j['amount'])print(sum) [{'name': 'a…