简体   繁体   English

Java Derby SQL连接

[英]Java Derby SQL Join

I have 3 tables: 我有3张桌子:

APPLICATION - 应用-

ID (PK)
DEVELOPER
GENRE
DESCRIPTION
POPULARITY
COST

CUSTOMER - 客户-

ID (PK)
FIRSTNAME
SURNAME
ADDRESS
TOWN
POSTCODE
PROFESSION

CUSTOMER_PURCHASES - CUSTOMER_PURCHASES-

TRANSACTION_ID (PK)
CUSTOMER_ID (FK)
APPLICATION_ID (FK)

I have a method that allows a CUSTOMER to purchase an APPLICATION. 我有一种允许客户购买应用程序的方法。 The method populates the table CUSTOMER_PURCHASES with an auto genereated Transaction_ID + CUSTOMER_ID (Provided by the customer table) + APPLICATION_ID (Provided by the application table). 该方法使用自动生成的Transaction_ID + CUSTOMER_ID(由客户表提供)+ APPLICATION_ID(由应用程序表提供)填充表CUSTOMER_PURCHASES。

I need the SQL statement that gives me the output - 我需要提供输出的SQL语句-

Transaction ID: 501
Customer ID: 301
Name: Beatrice May
Application ID: 302
Application Cost: £1.00

The SQL query I have that doesn't work is: 我有行不通的SQL查询是:

SELECT TRANSACTION_ID,
       CUSTOMER.ID,
       CUSTOMER_ID,
       FIRSTNAME, 
       SURNAME, 
       APPLICATION_ID, 
       APPLICATION.COST 
FROM CUSTOMER, CUSTOMER_PURCHASES,APPLICATION WHERE CUSTOMER.ID = CUSTOMER_PURCHASES.CUSTOMER_ID

Thank you 谢谢

James 詹姆士

Use explicit join syntax 使用显式联接语法

SELECT TRANSACTION_ID,
       CUSTOMER.ID,
       CONCAT(FIRSTNAME, ' ',  SURNAME) AS Name, 
       APPLICATION.ID, 
       APPLICATION.COST 
FROM CUSTOMER
JOIN CUSTOMER_PURCHASES
ON CUSTOMER.ID = CUSTOMER_PURCHASES.CUSTOMER_ID
JOIN APPLICATION 
ON APPLICATION.ID = CUSTOMER_PURCHASES.APPLICATION_ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM