数据库有两个表: company:字段companyId,companyName 表:employee:字段employeeId,employeeName

,companyId写一条sql语句得到每个公司的员工数量
2025-05-15 16:33:12
推荐回答(3个)
回答1:

我来回答你的第二个问题。和ACM试题差不多的,典型的线性规划问题。
时间紧,写的仓促,没有严格测试。

源代码如下;
#include "stdio.h"
#include "conio.h"

int comCount=0;

void compress(int date[],int comp[],int n)
{
int i=0;
int count=0;

int deadwhile=0;
int isSameFlag=0;
for(i=0;i {
if(date[i]!=date[i+1]&&!isSameFlag)
{
comp[comCount]=date[i];
comCount++;
}
else if(date[i]==date[i+1]&&!isSameFlag)
{
isSameFlag=1;
count=0;
count++;
i++;
while(i {
if(date[i]==date[i+1])
{
count++;
i++;
isSameFlag=1;
}
else
{
isSameFlag=0;
break;
}
}
if(count>=3)
{
comp[comCount]=0;
comp[comCount+1]=count+1;
comp[comCount+2]=date[i];
comCount+=3;
count=0;
}
else
{
count=0;
}
}
}
if(!isSameFlag)
{
comp[comCount]=date[i];

}
else
{
comCount--;
}
}

main()
{
const int ArrayLenth=22;
int a[22]={ 12,12,12,12,12,13,13,13,13,14,15,16,16,16,16,16,16,17,18,18,18,18};
/*int a[ArrayLenth]={12,13,14,15,16,16,16,16,16,16,17};*/
int b[ArrayLenth]={0};
int i=0;
compress(a,b,ArrayLenth);
for(i=0;i {
printf("%3d,",b[i]);
}
getch();
}

Dev-C++编译通过。
测试数据结果如下:
0, 5, 12, 0, 4, 13, 14, 15, 0, 6, 16, 17, 0, 4, 18,
楼主给的数据测试如下;
12, 13, 14, 15, 0, 6, 16, 17,
时间复杂度:0(n)
祝你好运!
如果写在项目里面一定要严格测试啊。

回答2:

select a.companyld,count(*) from company a left join employee b on a.companyid = b.companyid
group by a.companyid

回答3:

老兄把你这题结了 再提一个问吧