通过查询语句select * from user where id=1
我不知道你这个username指的是不是字段,如果是要取出表中某个字段的值。
可以通过select 字段名1,字段名2 ... from user where id=1。
-- MS sql server2005以上,ORACLE
select * from (
select row_number() over ( order by starttime asc) as rownum,* from steriworkrecord
where starttime between '2013-11-1' and '2013-12-31'
) a
where rownum between 2 and 10
-- 【注意( order by starttime asc)是你排序的方式asc升序,desc降序】
-- ORACLE还可以
select * from (
select rownum as n,* from steriworkrecord
where starttime between '2013-11-1' and '2013-12-31'
) a
where a.n between 2 and 10
-- MYSQL,postgreSQL似乎只能标量子查询
SELECT *FROM (
SELECT a.*,(
SELECT count(*) FROM steriworkrecordb WHERE b.ID<= a.ID) AS n
from steriworkrecorda
) ts
where ts.n between 2 and 10
-- 【注意b.ID<= a.ID 其中ID换成你的主键名称】
代码如下:
select * from tbl_DPImg where ID in (select min(ID) from tbl_DPImg group by DPID)
处理后结果为:
查找表中多余的重复记录,重复记录是根据单个字段(teamId)来判断
select * from team where teamId in (select teamId from team group by teamId having count(teamId) >1)
删除表中多余的重复记录,重复记录是根据单个字段(teamId)来判断,只留有rowid最小的记录
delete from team where
teamName in(select teamName from team group by teamName having count(teamName) >1)
and teamId not in (select min(teamId) from team group by teamName having count(teamName)>1)
扩展资料
数据记录筛选:
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语句大全
可用group by…having来实现。
可做如下测试:
1、创建表插入数据:
create table test
(id int,
name varchar(10))
insert into test values (1,'张三')
insert into test values (2,'李四')
insert into test values (3,'张三')
insert into test values (4,'王五')
insert into test values (5,'赵六')
其中name是张三的有两行,也就是重复行。
2、执行sql语句如下:
select * from test where name in
(select name from test group by name having COUNT(*)>1)
结果如图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)