所以我有一个主表产品,其中有一个ID作为主键。我想使用此ID链接到另一个表,其中包含此主键ID的多个副本。问题是,当我加入时,我会得到很多重复的值。
这是我的SQL语句:
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class StackerMain extends Applet implements Runnable, KeyListener,
MouseListener, MouseMotionListener{
//ADD MUSIC HERE//
/////////////////
//public StackerBlocks((RectangularShape s, Color c, int n, int rn, int x, int w, int h, int lr, int r){
private StackerBlocks block1;
private boolean gameOver;
private int score;
private boolean movingLeft;
private boolean movingRight;
private Thread stackerAnimator;
private int delay;
public int blockHeight = this.getSize().height/10;
public int blockWidth = this.getSize().width/10 ;
String playerName;
public void init(){
//Put Music Here
///////////////
playerName = JOptionPane.showInputDialog(this, "Your Name");
block1 = new StackerBlocks(new Rectangle2D.Double(), Color.MAGENTA,
3, 5, 500, blockWidth, blockHeight, -1, 1);
delay = 200 * block1.getRowNum();
this.setFocusable(true);
this.addKeyListener(this);
this.addMouseListener(this);
this.addMouseMotionListener(this);
score = 0;
gameOver = false;
movingLeft = true;
movingRight = false;
}
public void start(){
stackerAnimator = new Thread(this);
stackerAnimator.start();
}
public void stop(){
stackerAnimator = null;
}
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D) g;
if (!gameOver){
g2.setColor(block1.getColor());
g2.fill(block1.getShape());
g2.draw(block1.getShape());
g2.setFont(new Font("Times New Roman", Font.BOLD, 20));
g2.drawString("" + playerName + ": " + score, 5, 15);
}
else{
g2.drawString("GAME OVER, Score: " + score, this.getWidth()/2 - 10, this.getHeight()/2 - 8);
}
}
public void run(){
while(Thread.currentThread() == stackerAnimator && !gameOver){
block1.moveShape();
if (movingLeft){
block1.setX(block1.getX() - block1.getWidth());
if (block1.getX() <= 0){
block1.setX(0);
movingLeft = false;
movingRight = true;
block1.changeHorizontalDirection();
}
}
if (movingRight){
block1.setX(block1.getX() + block1.getWidth());
if (block1.getX() + block1.getWidth() >= this.getWidth()){
block1.setX(this.getWidth() - block1.getWidth());
movingRight = false;
movingLeft = true;
block1.changeHorizontalDirection();
}
}
repaint();
try{
Thread.sleep(delay);
}
catch(InterruptedException e){
break;
}
}
}
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == KeyEvent.VK_SPACE){
if (movingRight){
movingRight = false;
block1.setRun(0);
}
if (movingLeft){
movingLeft = false;
block1.setRun(0);
}
}
}
@Override
public void keyReleased(KeyEvent k) {
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
这是我当前的结果集:
http://i.imgur.com/MGFJRKu.png
我正在寻找类似这样的东西(其中空格为空或空): http://i.imgur.com/hf8tq9k.png
是否可以不用多个select语句?
答案 0 :(得分:1)
第二张图片中显示的输出不是一整套规范化的数据库记录。他们中的大多数人并不是自己的意思,因为他们缺少大部分数据。
看起来你要做的是让你的查询输出在显示时看起来更好,但这是正在进行显示的程序的工作,而不是SQL查询。
例如,您可以将SQL数据加载到Excel电子表格中,然后使用条件格式隐藏额外的重复条目(有关如何执行此操作的示例,请参阅:http://www.techrepublic.com/blog/windows-and-office/a-quick-trick-for-hiding-duplicate-excel-values/)