查询一个表中某两个字段的相同数据代码是:Select Name,ID From A group by Name,ID having count (*)>1。
结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;
sql 语句就是对数据库进行操作的一种语言。
sql="select * from 数据表 where字段名=字段值 order by字段名[desc]"(按某个字段值降序排列,默认升序ASC);
sql="select * from 数据表 where字段名like '%字段值%' order by 字段名 [desc]";
sql="select top 10 * from 数据表 where字段名=字段值 order by 字段名 [desc]";
sql="select top 10 * from 数据表 order by 字段名 [desc]";
sql="select * from 数据表 where字段名in ('值1','值2','值3')";
sql="select * from 数据表 where字段名between 值1 and 值2"。
sql语句:
更新:update table1 set field1=value1 where 范围;
查找:select * from table1 where field1 like '%value1%' (所有包含'value1'这个模式的字符串);
排序:select * from table1 order by field1,field2 [desc];
求和:select sum(field1) as sumvalue from table1;
平均:select avg(field1) as avgvalue from table1;
最大:select max(field1) as maxvalue from table1;
最小:select min(field1) as minvalue from table1[separator]。
除重
select distinct A.ID AS AID,A.Name AS AName,B.ID AS BID,B.Name AS BName from A inner join B on(A.Name=B.Name and A.ID=B.ID)
不除重
select A.ID AS AID,A.Name AS AName,B.ID AS BID,B.Name AS BName from A inner join B on(A.Name=B.Name and A.ID=B.ID)
select * from A
inner join B on A.Name = B.Name and A.ID = B.ID
where A.Name = '张三' and A.ID = '008'
内连接即可
Select Name,ID From A group by Name,ID having count (*)>1
select name,id,count(*) from a group by name,id