良好的解决方案和减法并且可以实现查询正在使用此但我有一个问题是禁止我减去负数例如4-6 = -2我想做的是只有我重新进行直到它达到0并且我重置计数器块,直到那个方法我可以实现道歉,如果你使用相同的问题这是我的查询用来实现减法
//Uses a cout to inform user will be using the number 412 as an example.
//Uses a cout to explain to user the number needs to be reversed.
cout << "Alright, let's walk through an example, using the number 412." << endl;
int numExample = 412;
cout << "Please input 412" << endl;
cin >> numExample;
cout << "First, the number 412 is reversed." << endl;
//The following is done for reversing the number 412:
int reverseNum = 0, remainder = 0;
while (numExample)
{
remainder = numExample % 10;
reverseNum = (reverseNum * 10) + remainder;
numExample = numExample / 10;
}
cout << "The reverse of 412 is " << reverseNum << endl;
cout << "Next, we want to subtract the reverse of the original number from its reverse" << endl;
cout << "This gives us 198" << endl;
cout << "From there, we want to reverse 198." << endl;
//The same procedure is used to reverse 198
int numExample2 = 198;
cout << "Please enter 198" << endl;
cin >> numExample2;
int reverseNum2 = 0, remainder2 = 0;
while (numExample2)
{
remainder2 = numExample2 % 10;
reverseNum2 = (reverseNum2 * 10) + remainder2;
numExample2 = numExample2 / 10;
}
cout << "The reverse of 198 is " << reverseNum2 << endl;
int magicNumber = (reverseNum2 + numExample2);
cout << "Following that, we want to add 891 to 189 which gives us " << magicNumber << endl;
答案 0 :(得分:0)
尝试编写这样的查询:
update Equipo
JOIN Historial on
Equipo.id=Historial.id
set Equipo.horasmotor=(Equipo.horasmotor - Historial.horasTrabajadas)
试试这个:
Update Equipo
JOIN Historial
where Historial.id=1
set Equipo.horasmotor= (CAST(Equipo.horasmotor AS INT) - CAST(Historial.horasTrabajadas AS INT))