mysql datetime选择问题。
我的桌子check_time:
count = 1
start = 23:57:45
end = 00:02:10
count = 2
start = 00:02:45
end = 00:07:10
我尝试了这个查询:
select count
from check_time
where start <= DATE_FORMAT(now(), '%H:%i:%s')
and end >= DATE_FORMAT(now(), '%H:%i:%s');
我希望现在()=“23:57:45”在“00:02:10”之间选择 - &gt; count = 1
仅限于计数1。
但完美地完成其他计数2~100 ..
抱歉我的英语不好。答案 0 :(得分:0)
很大程度上取决于您实际定义列public class GameLauncher {
public static void main(String[] args) {
GuessGame game = new GuessGame();
game.startGame();
}
}
和import java.util.Random;
public class Player {
int number = 0; //Where the guess goes
public void guess() {
//random1 is in GuessGame
Random random2 = new Random();
int number = random2.nextInt(10);
System.out.println("I'm guessing " + number);
}
}
的方式。我假设它们是以下的“时间”列。
另请注意,为了避免使用我无法控制的服务器时间问题,我使用了@curtime,但在代码中,您应该使用CURTIME()代替。请参阅SQL Fiddle
上的演示演示 import java.util.Random;
public class GuessGame {
//Guessgame has three instance variables for the three Player objects
Player p1;
Player p2;
Player p3;
public void startGame() {
//Create three Player objects and assign them to the three Player instance variables
p1 = new Player();
p2 = new Player();
p3 = new Player();
//Declare three variables to hold the three guesses the players make
int guessp1 = 0;
int guessp2 = 0;
int guessp3 = 0;
//Declare three variables to hold a true or false based on the player's answer
boolean p1isRight = false;
boolean p2isRight = false;
boolean p3isRight = false;
//Make a "target" number that the players have to guess
Random random = new Random();
//Generate a number between 0 and 9
int targetNumber = random.nextInt(10);
System.out.println("I'm thinking of a number between 0 and 9...");
while (true) {
System.out.println("Number to guess is " + targetNumber);
//Call each player's guess() method
p1.guess();
p2.guess();
p3.guess();
/*
Get each player's guess (the result of their guess() method
running) by accessing the number variable of each player
*/
guessp1 = p1.number;
guessp2 = p2.number;
guessp3 = p3.number;
System.out.println("Player one guessed " + guessp1);
System.out.println("Player two guessed " + guessp2);
System.out.println("Player three guessed " + guessp3);
/*
Check each player's guess to see if it matches the target number. If a player is right, then set that player's variable to be true (remember, we set it false by default)
*/
if (guessp1 == targetNumber) {
p1isRight = true;
}
if (guessp2 == targetNumber) {
p2isRight = true;
}
if (guessp3 == targetNumber) {
p3isRight = true;
}
//If player one OR player two OR player three is right... (the || operator means OR)
if (p1isRight || p2isRight || p3isRight) {
System.out.println("We have a winner!");
System.out.println("Player one got it right? " + p1isRight);
System.out.println("Player two got it right? " + p2isRight);
System.out.println("Player three got it right? " + p3isRight);
System.out.println("Game is over.");
break; //Game over, so break out of the loop
}
else {
//We must keep going because nobody got it right!
System.out.println("Players will have to try again.");
} //end if/else
} //end loop
} //end method
} //end class
查询1 :
public void calcTotal() {
total = super.calcTotal();
if (amount > 5) {
total = total - (15/100.0 * total);
}
}
<强> Results 强>:
total
查询2 :
start
<强> Results 强>:
end