select name,id,actor,content from temp a inner join (select min(id),name from temp group by name) b on a.id=b.id
select name,id,actor,content from table as T where id =(select min(id) from table where name=T.name)
shuai45(付出总有回报,要做就做最好.) --------------------------你的写法有问题 select name,id,actor,content from table as T where id in (select min(id) from table where name=T.name) ---这个地方要用in不是等号
各子表的数据是不会重复的,因为多表关联而产生的重复又怎么处理(产生原因是a表的program_id会同时属于vod_menu2program里的多个program_menu_id): 原语句是 select distinct a.program_id,a.name,a.director,a.playactor,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1 现在因为要加输出content select distinct a.program_id,a.name,a.director,a.playactor,a.content,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1 就不能用distinct了我用上面各位的方法无法解决这个问题
各子表的数据是不会重复的,因为多表关联而产生的重复又怎么处理(产生原因是a表的program_id会同时属于vod_menu2program里的多个program_menu_id): 原语句是 select distinct a.program_id,a.name,a.director,a.playactor,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1 现在因为要加输出content select distinct a.program_id,a.name,a.director,a.playactor,a.content,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1 就不能用distinct了我用上面各位的方法无法解决这个问题 各位再帮我想想
你的sql 写的好乱~看看下面的能否执行select a.program_id,a.name,a.director,a.playactor,a.content,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1 and a.program_id in (select min(a.program_id) from vod_program where name=a.name)
大哥你提问的时候 能不能将长的sql写的结构化一些,让人有心情看 如: select ......... from ........ inner join ......... inner join ......... where ............... group by ...........
from temp a inner join (select min(id),name from temp group by name) b on a.id=b.id
where id =(select min(id) from table where name=T.name)
select name,id,actor,content from table as T
where id in (select min(id) from table where name=T.name) ---这个地方要用in不是等号
的很好,要按大的改成max
原语句是
select distinct a.program_id,a.name,a.director,a.playactor,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1
现在因为要加输出content
select distinct a.program_id,a.name,a.director,a.playactor,a.content,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1
就不能用distinct了我用上面各位的方法无法解决这个问题
原语句是
select distinct a.program_id,a.name,a.director,a.playactor,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1
现在因为要加输出content
select distinct a.program_id,a.name,a.director,a.playactor,a.content,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1
就不能用distinct了我用上面各位的方法无法解决这个问题
各位再帮我想想
a.program_id in (select min(a.program_id) from vod_program where name=a.name)
如:
select .........
from ........
inner join .........
inner join .........
where
...............
group by ...........