php投票项目的票数和时间怎么一起入库
用php的sql语句,就是插入和修改怎么在一个函数里一起用。求解
用外连接实现,如下:
create table person
(perno varchar(8) not null)
create table temp
(perno varchar(8) not null,
cou integer not null
)
insert into person
select 'A '
union
select 'B'
union
select 'C'
union
select 'D'
insert into temp
select 'A',1
union all
select 'A',1
union
select 'B',1
union
select 'C',1
select * from temp
select a.perno,COUNT(b.perno)as '票数' from person a left join temp b on a.perno = b.perno
group by a.perno;
显示结果连包括0票的人员都会统计出来。 本回答由电脑网络分类达人 张弦推荐举报| 答案纠错 | 评论 0 2糖糖寳寳 采纳率:92% 来自团队:百度知道电脑团 擅长: 医疗健康 电脑/网络 人体常识 精神心理科
其他回答楼上的语句没有毛病,不过搂主提供了userinfo表,这里如果某个用户没有得票的话,就统计不上了,还是join一把比较好点。另外直接查询的话结果体现不出来名次
select identity(int,1,1) as [名次],a.username as [用户名],count(*) as [票数]
into #temporders
from userinfo a left join votes b
on a.username=b.username
group by a.username
order by [票数] desc
select *
from #temporders
order by [名次]