mysql查询--35分
mysql 中一个表中字段如下: id value create_time 三个字段
如数据有:
1 test1 2009-9-10
1 test2 2009-9-11
2 testg 2009-9-10
3 testu 2009-9-11
3 testn 2009-9-10
我要想得到的结果是当id相同时,只取create_time为最大的一条数据,这样取得结果会是
1 test2 2009-9-11
2 testg 2009-9-10
3 testu 2009-9-11
请问这个sql语句应该怎么写?
谁先给出正确语句,分全给他......急用中
帮到你顶下。。呵呵。
SQL code:
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
例二:
select * from testtable
where numeber in (select number from people group by number having count(number) > 1 )
可以查出testtable表中number相同的记录
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq) in (sele
相关问答:
我之前导入的数据库,现在删除不了,用了命令行和工具都不行,重启也不行,这是为什么呢?
你是如何删除的?
有什么提示?
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
......
大家好,我在用sql创建视图的时候,出现问题了,代码如下:
use student_info;
create view results_view as
select r.student_id as 学号, s.student_name as 姓名, c.course_name as 课程名称, r.res ......
MYSQL 截取一个数据表中,某一个字段(fulltext) 的前三百个字符,放到该表下另一个字段(introtxt)里.
求实现这个效果的命令
SQL code:
update 表 set introtxt=left(`fulltext`,300);
顶,学习
SQL code: ......
SQL code:
--建立临时表,问题1
create TEMPORARY table tmp_table(s1 int,s2 varchar(30))
--select * from tmp_table
--建立临时变量,问题2
set @v=0;
--循环执行插入操作,问题3
while @v<20 do
......