选择多个 table 时在数据库上执行查询时出错
Error when performing query on database when more than one table is selected
我正在使用最新版本的 PHPMYADMIN 和 XAMPP,这是错误:
Fatal error: Uncaught TypeError: PhpMyAdmin\DatabaseInterface::getColumns(): Argument #2 ($table) must be of type string, null given, called in D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php on line 187 and defined in D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\DatabaseInterface.php:893 Stack trace: #0 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(187): PhpMyAdmin\DatabaseInterface->getColumns('bankschema', NULL) #1 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(1536): PhpMyAdmin\Sql->resultSetContainsUniqueKey('bankschema', NULL, Array) #2 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(1856): PhpMyAdmin\Sql->getQueryResponseForResultsReturned(Object(mysqli_result), Array, 'bankschema', NULL, NULL, Object(PhpMyAdmin\Display\Results), './themes/pmahom...', 2, 2, NULL, NULL, NULL, 'SELECT accounts...', NULL) #3 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(1703): PhpMyAdmin\Sql->executeQueryAndGetQueryResponse(Array, false, 'bankschema', NULL, false, NULL, NULL, NULL, NULL, 'index.php?route...', './themes/pmahom...', NULL, NULL, 'SELECT accounts...', NULL) #4 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Controllers\Database\QueryByExampleController.php(133): PhpMyAdmin\Sql->executeQueryAndSendQueryResponse(Array, false, 'bankschema', NULL, false, NULL, NULL, NULL, NULL, 'index.php?route...', './themes/pmahom...', NULL, NULL, 'SELECT accounts...', NULL) #5 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Routing.php(187): PhpMyAdmin\Controllers\Database\QueryByExampleController->index(Array) #6 D:\Uni\SDS\XAMPP\phpMyAdmin\index.php(18): PhpMyAdmin\Routing::callControllerForRoute('/database/qbe', Object(FastRoute\Dispatcher\GroupCountBased), Object(Symfony\Component\DependencyInjection\ContainerBuilder)) #7 {main} thrown in D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\DatabaseInterface.php on line 893
我的SQL代码:
# Creating the database
DROP DATABASE IF EXISTS bankSchema;
CREATE DATABASE bankSchema;
USE bankSchema;
# Setting up the tables
CREATE TABLE phone_numbers(
number_ID INT NOT NULL AUTO_INCREMENT,
phone_number VARCHAR(12) NOT NULL UNIQUE,
PRIMARY KEY (number_ID)
);
CREATE TABLE addresses(
address_ID INT NOT NULL AUTO_INCREMENT,
county VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
street_name VARCHAR(100) NOT NULL,
house_number VARCHAR(10) NOT NULL,
postcode VARCHAR(8) NOT NULL,
PRIMARY KEY (address_ID)
);
CREATE TABLE accounts(
account_ID INT NOT NULL AUTO_INCREMENT,
account_number INT(8) NOT NULL UNIQUE,
sort_code INT(6) NOT NULL,
opening_balance DECIMAL(12,2) NOT NULL,
CHECK(opening_balance > 50),
PRIMARY KEY (account_ID)
);
CREATE TABLE customers(
customer_ID INT NOT NULL AUTO_INCREMENT,
address_ID INT NOT NULL,
number_ID INT NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
date_of_birth DATE NOT NULL,
PRIMARY KEY (customer_ID),
FOREIGN KEY (address_ID) REFERENCES addresses(address_ID),
FOREIGN KEY (number_ID) REFERENCES phone_numbers(number_ID)
);
CREATE TABLE customer_accounts(
account_ID INT NOT NULL,
customer_ID INT NOT NULL,
CONSTRAINT PrimaryKey_customer_accounts PRIMARY KEY (account_ID, customer_ID),
FOREIGN KEY (account_ID) REFERENCES accounts(account_ID),
FOREIGN KEY (customer_ID) REFERENCES customers(customer_ID)
);
CREATE TABLE transactions(
transaction_ID INT NOT NULL AUTO_INCREMENT,
account_ID INT NOT NULL,
transaction_value DECIMAL(12,2) NOT NULL,
transaction_type ENUM("incoming", "outgoing") NOT NULL,
transaction_date DATETIME NOT NULL,
PRIMARY KEY (transaction_ID),
FOREIGN KEY (account_ID) REFERENCES accounts(account_ID)
);
CREATE TABLE loans(
loan_ID INT NOT NULL AUTO_INCREMENT,
account_ID INT NOT NULL,
payment_rate DECIMAL(12,2) NOT NULL,
loan_length INT NOT NULL,
first_payment_date DATE NOT NULL,
monthly_due_date INT NOT NULL,
PRIMARY KEY (loan_ID),
FOREIGN KEY (account_ID) REFERENCES accounts(account_ID)
);
CREATE TABLE loan_transactions(
payment_ID INT NOT NULL AUTO_INCREMENT,
loan_ID INT NOT NULL,
transaction_ID INT NOT NULL,
PRIMARY KEY (payment_ID),
FOREIGN KEY (loan_ID) REFERENCES loans(loan_ID),
FOREIGN KEY (transaction_ID) REFERENCES transactions(transaction_ID)
);
DELIMITER $$
CREATE PROCEDURE GetcustomerBalance(
IN first_name varchar(64),
IN last_name varchar(64),
IN date_of_birth date
)
BEGIN
SELECT accounts.accountnumber, accounts.sort_code, (accounts.opening_balance + transactions_group.net_change) as Balance
FROM customeraccounts
INNER JOIN customers ON customers.first_name = first_name AND customers.last_name = last_name AND customers.DOB = date_of_birth
INNER JOIN accounts ON accounts.account_ID = customeraccounts.account_ID
RIGHT JOIN (
SELECT account_ID, SUM(transactions.transactions_value) as net_change
FROM transactions
group BY transactions.account_ID
) transactions_group ON transactions_group.account_ID = accounts.account_ID
LIMIT 1;
END $$
CREATE PROCEDURE GetTotalOutstandings()
BEGIN
SELECT SUM(accounts.opening_balance + transactions_group.net_change) AS TotalOutstandings
FROM accounts
RIGHT JOIN (
SELECT account_ID, SUM(transactions.transaction_value) as net_change
FROM transactions
GROUP BY transactions.account_ID
) transactions_group ON transactions_group.account_ID = accounts.account_ID
LIMIT 1;
END $$
DELIMITER ;
# Adding all of the data to the tables
# Adding all the phone numbers
INSERT INTO phone_numbers (phone_number) VALUES ("07726711546");
INSERT INTO phone_numbers (phone_number) VALUES ("07927715584");
INSERT INTO phone_numbers (phone_number) VALUES ("07131015372");
INSERT INTO phone_numbers (phone_number) VALUES ("07918095513");
INSERT INTO phone_numbers (phone_number) VALUES ("07847774296");
INSERT INTO phone_numbers (phone_number) VALUES ("07732710928");
INSERT INTO phone_numbers (phone_number) VALUES ("07043641210");
INSERT INTO phone_numbers (phone_number) VALUES ("07072150657");
INSERT INTO phone_numbers (phone_number) VALUES ("07781737664");
INSERT INTO phone_numbers (phone_number) VALUES ("07789935038");
# Adding all the addresses
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Kent", "Tunbridge Wells", "New Street", "92", "TN40 8BF");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "London", "Park Avenue", "73", "N62 3GB");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Berkshire", "Reading", "South Street", "92", "RG79 7FN");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Denbighshire", "Llandudno", "The Grove", "63", "LL94 1NM");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Wiltshire", "Swindon", "South Street", "80", "SN49 7PW");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "Enfield", "South Street", "46", "EN69 0JM");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Midlothian", "Edinburgh", "South Street", "92", "EH85 0FE");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "Romford", "South Street", "48", "RM73 4MK");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "London", "South Street", "15", "E13 8XR");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Lancashire", "Preston", "South Street", "64", "PR93 2YH");
# Adding all the accounts
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (06725303, 774009, 10000.87);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (52214025, 774009, 100.00);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (02654236, 774009, 1054.62);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (32951358, 774009, 5038.21);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (83565092, 774009, 2457.00);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (74914912, 774009, 1040.23);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (24918996, 774009, 3000.85);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (02897170, 774009, 2961.00);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (05914777, 774009, 576.44);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (86755716, 774009, 307.95);
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (5, 7, "Josey", "Dunkerly", "1976-07-02");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (3, 2, "Dominic", "Semken", "1988-01-15");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (2, 5, "Almeda", "Laffranconi", "2000-06-13");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (1, 8, "Sondra", "Stockall", "1988-06-23");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (10, 6, "Sayres", "Hought", "1978-09-21");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (7, 3, "Robinet", "Anning", "1995-12-25");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (6, 1, "Sansone", "Halwood", "1993-05-13");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (9, 4, "James", "Nairns", "1969-03-17");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (8, 9, "Lexi", "Bater", "1986-09-19");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (4, 10, "Ulla", "Celiz", "1997-10-21");
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (1, 4);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (2, 9);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (3, 6);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (4, 3);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (5, 8);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (6, 7);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (7, 10);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (8, 2);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (9, 5);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (10, 1);
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(6,430,"incoming","2022-01-30"),
(6,811,"incoming","2021-12-21"),
(9,966,"incoming","2022-02-19"),
(9,881,"outgoing","2022-03-16"),
(4,809,"outgoing","2021-12-09"),
(4,87,"incoming","2021-03-29"),
(3,793,"incoming","2022-01-25"),
(1,300,"outgoing","2021-10-10"), #8
(2,502,"outgoing","2021-01-26"),
(3,565,"incoming","2021-01-14");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(6,81,"incoming","2021-01-19"),
(8,119,"outgoing","2021-08-17"),
(9,737,"incoming","2021-12-29"),
(1,914,"outgoing","2022-01-13"),
(2,460,"incoming","2021-11-21"),
(2,401,"incoming","2021-11-14"),
(3,981,"outgoing","2021-07-16"),
(1,305,"incoming","2021-06-27"),
(4,952,"incoming","2021-03-25"),
(6,631,"outgoing","2021-07-07");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(5,337,"incoming","2022-02-18"),
(5,627,"outgoing","2022-01-21"),
(7,369,"outgoing","2021-08-20"),
(8,159,"incoming","2021-07-11"),
(8,828,"outgoing","2021-09-30"),
(5,792,"outgoing","2022-03-11"),
(7,908,"incoming","2022-02-27"),
(4,538,"incoming","2022-03-08"),
(4,434,"incoming","2021-04-16"),
(4,597,"outgoing","2022-03-25");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(8,517,"outgoing","2021-01-30"),
(4,439,"outgoing","2021-09-04"),
(7,780,"incoming","2021-01-02"),
(5,90,"incoming","2021-02-21"),
(7,182,"incoming","2021-11-26"),
(10,975,"outgoing","2022-01-06"),
(8,358,"incoming","2021-01-13"),
(4,91,"incoming","2021-03-04"),
(6,887,"incoming","2021-11-14"),
(7,609,"incoming","2021-04-15");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(2,213,"incoming","2021-12-02"),
(7,280,"incoming","2021-02-17"),
(9,366,"outgoing","2021-04-08"),
(3,369,"outgoing","2022-03-14"),
(5,543,"outgoing","2021-04-06"),
(8,385,"outgoing","2021-10-26"),
(2,471,"outgoing","2021-11-02"),
(3,820,"outgoing","2021-06-17"),
(8,582,"incoming","2022-01-07"),
(3,942,"incoming","2022-02-28");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(6,612,"outgoing","2021-11-22"),
(2,802,"outgoing","2021-04-10"),
(10,454,"incoming","2021-03-07"),
(10,959,"outgoing","2021-01-27"),
(7,961,"outgoing","2021-03-22"),
(7,408,"outgoing","2021-12-20"),
(9,150,"outgoing","2022-01-07"), # 57
(6,378,"outgoing","2021-11-11"),
(10,902,"outgoing","2021-07-29"),
(6,402,"incoming","2021-07-03");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(8,99,"incoming","2021-07-26"),
(2,402,"incoming","2021-12-21"),
(9,211,"incoming","2021-06-24"),
(10,561,"outgoing","2022-03-25"),
(5,779,"incoming","2021-03-30"),
(7,277,"incoming","2021-07-08"),
(6,786,"outgoing","2021-05-26"),
(10,858,"incoming","2021-07-08"),
(5,530,"incoming","2021-03-16"),
(6,644,"incoming","2021-06-19");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(1,967,"outgoing","2021-10-12"),
(3,684,"outgoing","2022-01-31"),
(7,108,"incoming","2021-03-20"),
(3,133,"outgoing","2021-11-14"),
(7,200,"outgoing","2021-11-15"), # 75
(6,109,"outgoing","2021-06-30"),
(7,554,"incoming","2021-06-13"),
(2,819,"outgoing","2021-01-16"),
(4,442,"incoming","2021-03-29"),
(4,72,"incoming","2021-01-17");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(3,486,"outgoing","2022-01-19"),
(9,805,"incoming","2021-12-16"),
(2,159,"incoming","2021-01-15"),
(8,566,"incoming","2021-03-16"),
(1,760,"incoming","2021-11-12"),
(5,470,"outgoing","2021-10-19"), # 86
(6,824,"incoming","2021-06-08"),
(3,976,"incoming","2021-04-18"),
(8,79,"incoming","2021-02-07"),
(7,675,"outgoing","2021-05-02");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(4,500,"outgoing","2021-03-05"), #91
(2,542,"outgoing","2021-03-10"),
(7,384,"incoming","2021-12-31"),
(2,325,"incoming","2021-10-19"),
(3,413,"outgoing","2021-08-06"),
(8,73,"outgoing","2021-04-08"),
(9,510,"incoming","2022-02-23"),
(3,950,"outgoing","2021-05-17"),
(6,503,"incoming","2021-01-26"),
(9,154,"incoming","2021-08-29");
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (1, 300, 21, "2021-02-05", 5);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (4, 500, 12, "2021-03-21", 21);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (5, 470, 15, "2021-09-19", 19);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (7, 200, 25, "2021-10-15", 15);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (9, 150, 29, "2021-11-07", 7);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 8);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 57);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 75);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 86);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 91);
我正在尝试执行的查询:
SELECT accounts.account_number, customers.first_name, customers.last_name, loans.monthly_due_date
FROM customer_accounts
INNER JOIN customers ON customers.customer_ID = customer_accounts.customer_ID
INNER JOIN accounts ON accounts.account_ID = customer_accounts.account_ID
INNER JOIN loans ON loans.account_ID = accounts.account_ID
WHERE loans.monthly_due_date <=7
我试过重新安装,使用不同的版本,我禁用了 UAC,我在另一台机器上测试了我的代码,它可以工作,但在我的电脑上不行,碰巧我尝试用多个 table。我试过删除缓存并使用不同的浏览器。
这看起来像是 phpmyadmin 中的错误:
https://github.com/phpmyadmin/phpmyadmin/issues/17001
里程碑是 5.1.2 得到更正,它在 11 天前发布(截至此答案)。试试 phpmyadmin 5.1.2,我相信它应该得到纠正。
我正在使用最新版本的 PHPMYADMIN 和 XAMPP,这是错误:
Fatal error: Uncaught TypeError: PhpMyAdmin\DatabaseInterface::getColumns(): Argument #2 ($table) must be of type string, null given, called in D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php on line 187 and defined in D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\DatabaseInterface.php:893 Stack trace: #0 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(187): PhpMyAdmin\DatabaseInterface->getColumns('bankschema', NULL) #1 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(1536): PhpMyAdmin\Sql->resultSetContainsUniqueKey('bankschema', NULL, Array) #2 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(1856): PhpMyAdmin\Sql->getQueryResponseForResultsReturned(Object(mysqli_result), Array, 'bankschema', NULL, NULL, Object(PhpMyAdmin\Display\Results), './themes/pmahom...', 2, 2, NULL, NULL, NULL, 'SELECT accounts...', NULL) #3 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Sql.php(1703): PhpMyAdmin\Sql->executeQueryAndGetQueryResponse(Array, false, 'bankschema', NULL, false, NULL, NULL, NULL, NULL, 'index.php?route...', './themes/pmahom...', NULL, NULL, 'SELECT accounts...', NULL) #4 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Controllers\Database\QueryByExampleController.php(133): PhpMyAdmin\Sql->executeQueryAndSendQueryResponse(Array, false, 'bankschema', NULL, false, NULL, NULL, NULL, NULL, 'index.php?route...', './themes/pmahom...', NULL, NULL, 'SELECT accounts...', NULL) #5 D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\Routing.php(187): PhpMyAdmin\Controllers\Database\QueryByExampleController->index(Array) #6 D:\Uni\SDS\XAMPP\phpMyAdmin\index.php(18): PhpMyAdmin\Routing::callControllerForRoute('/database/qbe', Object(FastRoute\Dispatcher\GroupCountBased), Object(Symfony\Component\DependencyInjection\ContainerBuilder)) #7 {main} thrown in D:\Uni\SDS\XAMPP\phpMyAdmin\libraries\classes\DatabaseInterface.php on line 893
我的SQL代码:
# Creating the database
DROP DATABASE IF EXISTS bankSchema;
CREATE DATABASE bankSchema;
USE bankSchema;
# Setting up the tables
CREATE TABLE phone_numbers(
number_ID INT NOT NULL AUTO_INCREMENT,
phone_number VARCHAR(12) NOT NULL UNIQUE,
PRIMARY KEY (number_ID)
);
CREATE TABLE addresses(
address_ID INT NOT NULL AUTO_INCREMENT,
county VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
street_name VARCHAR(100) NOT NULL,
house_number VARCHAR(10) NOT NULL,
postcode VARCHAR(8) NOT NULL,
PRIMARY KEY (address_ID)
);
CREATE TABLE accounts(
account_ID INT NOT NULL AUTO_INCREMENT,
account_number INT(8) NOT NULL UNIQUE,
sort_code INT(6) NOT NULL,
opening_balance DECIMAL(12,2) NOT NULL,
CHECK(opening_balance > 50),
PRIMARY KEY (account_ID)
);
CREATE TABLE customers(
customer_ID INT NOT NULL AUTO_INCREMENT,
address_ID INT NOT NULL,
number_ID INT NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
date_of_birth DATE NOT NULL,
PRIMARY KEY (customer_ID),
FOREIGN KEY (address_ID) REFERENCES addresses(address_ID),
FOREIGN KEY (number_ID) REFERENCES phone_numbers(number_ID)
);
CREATE TABLE customer_accounts(
account_ID INT NOT NULL,
customer_ID INT NOT NULL,
CONSTRAINT PrimaryKey_customer_accounts PRIMARY KEY (account_ID, customer_ID),
FOREIGN KEY (account_ID) REFERENCES accounts(account_ID),
FOREIGN KEY (customer_ID) REFERENCES customers(customer_ID)
);
CREATE TABLE transactions(
transaction_ID INT NOT NULL AUTO_INCREMENT,
account_ID INT NOT NULL,
transaction_value DECIMAL(12,2) NOT NULL,
transaction_type ENUM("incoming", "outgoing") NOT NULL,
transaction_date DATETIME NOT NULL,
PRIMARY KEY (transaction_ID),
FOREIGN KEY (account_ID) REFERENCES accounts(account_ID)
);
CREATE TABLE loans(
loan_ID INT NOT NULL AUTO_INCREMENT,
account_ID INT NOT NULL,
payment_rate DECIMAL(12,2) NOT NULL,
loan_length INT NOT NULL,
first_payment_date DATE NOT NULL,
monthly_due_date INT NOT NULL,
PRIMARY KEY (loan_ID),
FOREIGN KEY (account_ID) REFERENCES accounts(account_ID)
);
CREATE TABLE loan_transactions(
payment_ID INT NOT NULL AUTO_INCREMENT,
loan_ID INT NOT NULL,
transaction_ID INT NOT NULL,
PRIMARY KEY (payment_ID),
FOREIGN KEY (loan_ID) REFERENCES loans(loan_ID),
FOREIGN KEY (transaction_ID) REFERENCES transactions(transaction_ID)
);
DELIMITER $$
CREATE PROCEDURE GetcustomerBalance(
IN first_name varchar(64),
IN last_name varchar(64),
IN date_of_birth date
)
BEGIN
SELECT accounts.accountnumber, accounts.sort_code, (accounts.opening_balance + transactions_group.net_change) as Balance
FROM customeraccounts
INNER JOIN customers ON customers.first_name = first_name AND customers.last_name = last_name AND customers.DOB = date_of_birth
INNER JOIN accounts ON accounts.account_ID = customeraccounts.account_ID
RIGHT JOIN (
SELECT account_ID, SUM(transactions.transactions_value) as net_change
FROM transactions
group BY transactions.account_ID
) transactions_group ON transactions_group.account_ID = accounts.account_ID
LIMIT 1;
END $$
CREATE PROCEDURE GetTotalOutstandings()
BEGIN
SELECT SUM(accounts.opening_balance + transactions_group.net_change) AS TotalOutstandings
FROM accounts
RIGHT JOIN (
SELECT account_ID, SUM(transactions.transaction_value) as net_change
FROM transactions
GROUP BY transactions.account_ID
) transactions_group ON transactions_group.account_ID = accounts.account_ID
LIMIT 1;
END $$
DELIMITER ;
# Adding all of the data to the tables
# Adding all the phone numbers
INSERT INTO phone_numbers (phone_number) VALUES ("07726711546");
INSERT INTO phone_numbers (phone_number) VALUES ("07927715584");
INSERT INTO phone_numbers (phone_number) VALUES ("07131015372");
INSERT INTO phone_numbers (phone_number) VALUES ("07918095513");
INSERT INTO phone_numbers (phone_number) VALUES ("07847774296");
INSERT INTO phone_numbers (phone_number) VALUES ("07732710928");
INSERT INTO phone_numbers (phone_number) VALUES ("07043641210");
INSERT INTO phone_numbers (phone_number) VALUES ("07072150657");
INSERT INTO phone_numbers (phone_number) VALUES ("07781737664");
INSERT INTO phone_numbers (phone_number) VALUES ("07789935038");
# Adding all the addresses
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Kent", "Tunbridge Wells", "New Street", "92", "TN40 8BF");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "London", "Park Avenue", "73", "N62 3GB");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Berkshire", "Reading", "South Street", "92", "RG79 7FN");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Denbighshire", "Llandudno", "The Grove", "63", "LL94 1NM");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Wiltshire", "Swindon", "South Street", "80", "SN49 7PW");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "Enfield", "South Street", "46", "EN69 0JM");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Midlothian", "Edinburgh", "South Street", "92", "EH85 0FE");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "Romford", "South Street", "48", "RM73 4MK");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Greater London", "London", "South Street", "15", "E13 8XR");
INSERT INTO addresses (county, city, street_name, house_number, postcode) VALUES ("Lancashire", "Preston", "South Street", "64", "PR93 2YH");
# Adding all the accounts
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (06725303, 774009, 10000.87);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (52214025, 774009, 100.00);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (02654236, 774009, 1054.62);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (32951358, 774009, 5038.21);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (83565092, 774009, 2457.00);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (74914912, 774009, 1040.23);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (24918996, 774009, 3000.85);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (02897170, 774009, 2961.00);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (05914777, 774009, 576.44);
INSERT INTO accounts (account_number, sort_code, opening_balance) VALUES (86755716, 774009, 307.95);
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (5, 7, "Josey", "Dunkerly", "1976-07-02");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (3, 2, "Dominic", "Semken", "1988-01-15");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (2, 5, "Almeda", "Laffranconi", "2000-06-13");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (1, 8, "Sondra", "Stockall", "1988-06-23");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (10, 6, "Sayres", "Hought", "1978-09-21");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (7, 3, "Robinet", "Anning", "1995-12-25");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (6, 1, "Sansone", "Halwood", "1993-05-13");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (9, 4, "James", "Nairns", "1969-03-17");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (8, 9, "Lexi", "Bater", "1986-09-19");
INSERT INTO customers (address_ID, number_ID, first_name, last_name, date_of_birth) VALUES (4, 10, "Ulla", "Celiz", "1997-10-21");
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (1, 4);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (2, 9);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (3, 6);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (4, 3);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (5, 8);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (6, 7);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (7, 10);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (8, 2);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (9, 5);
INSERT INTO customer_accounts (account_ID, customer_ID) VALUES (10, 1);
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(6,430,"incoming","2022-01-30"),
(6,811,"incoming","2021-12-21"),
(9,966,"incoming","2022-02-19"),
(9,881,"outgoing","2022-03-16"),
(4,809,"outgoing","2021-12-09"),
(4,87,"incoming","2021-03-29"),
(3,793,"incoming","2022-01-25"),
(1,300,"outgoing","2021-10-10"), #8
(2,502,"outgoing","2021-01-26"),
(3,565,"incoming","2021-01-14");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(6,81,"incoming","2021-01-19"),
(8,119,"outgoing","2021-08-17"),
(9,737,"incoming","2021-12-29"),
(1,914,"outgoing","2022-01-13"),
(2,460,"incoming","2021-11-21"),
(2,401,"incoming","2021-11-14"),
(3,981,"outgoing","2021-07-16"),
(1,305,"incoming","2021-06-27"),
(4,952,"incoming","2021-03-25"),
(6,631,"outgoing","2021-07-07");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(5,337,"incoming","2022-02-18"),
(5,627,"outgoing","2022-01-21"),
(7,369,"outgoing","2021-08-20"),
(8,159,"incoming","2021-07-11"),
(8,828,"outgoing","2021-09-30"),
(5,792,"outgoing","2022-03-11"),
(7,908,"incoming","2022-02-27"),
(4,538,"incoming","2022-03-08"),
(4,434,"incoming","2021-04-16"),
(4,597,"outgoing","2022-03-25");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(8,517,"outgoing","2021-01-30"),
(4,439,"outgoing","2021-09-04"),
(7,780,"incoming","2021-01-02"),
(5,90,"incoming","2021-02-21"),
(7,182,"incoming","2021-11-26"),
(10,975,"outgoing","2022-01-06"),
(8,358,"incoming","2021-01-13"),
(4,91,"incoming","2021-03-04"),
(6,887,"incoming","2021-11-14"),
(7,609,"incoming","2021-04-15");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(2,213,"incoming","2021-12-02"),
(7,280,"incoming","2021-02-17"),
(9,366,"outgoing","2021-04-08"),
(3,369,"outgoing","2022-03-14"),
(5,543,"outgoing","2021-04-06"),
(8,385,"outgoing","2021-10-26"),
(2,471,"outgoing","2021-11-02"),
(3,820,"outgoing","2021-06-17"),
(8,582,"incoming","2022-01-07"),
(3,942,"incoming","2022-02-28");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(6,612,"outgoing","2021-11-22"),
(2,802,"outgoing","2021-04-10"),
(10,454,"incoming","2021-03-07"),
(10,959,"outgoing","2021-01-27"),
(7,961,"outgoing","2021-03-22"),
(7,408,"outgoing","2021-12-20"),
(9,150,"outgoing","2022-01-07"), # 57
(6,378,"outgoing","2021-11-11"),
(10,902,"outgoing","2021-07-29"),
(6,402,"incoming","2021-07-03");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(8,99,"incoming","2021-07-26"),
(2,402,"incoming","2021-12-21"),
(9,211,"incoming","2021-06-24"),
(10,561,"outgoing","2022-03-25"),
(5,779,"incoming","2021-03-30"),
(7,277,"incoming","2021-07-08"),
(6,786,"outgoing","2021-05-26"),
(10,858,"incoming","2021-07-08"),
(5,530,"incoming","2021-03-16"),
(6,644,"incoming","2021-06-19");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(1,967,"outgoing","2021-10-12"),
(3,684,"outgoing","2022-01-31"),
(7,108,"incoming","2021-03-20"),
(3,133,"outgoing","2021-11-14"),
(7,200,"outgoing","2021-11-15"), # 75
(6,109,"outgoing","2021-06-30"),
(7,554,"incoming","2021-06-13"),
(2,819,"outgoing","2021-01-16"),
(4,442,"incoming","2021-03-29"),
(4,72,"incoming","2021-01-17");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(3,486,"outgoing","2022-01-19"),
(9,805,"incoming","2021-12-16"),
(2,159,"incoming","2021-01-15"),
(8,566,"incoming","2021-03-16"),
(1,760,"incoming","2021-11-12"),
(5,470,"outgoing","2021-10-19"), # 86
(6,824,"incoming","2021-06-08"),
(3,976,"incoming","2021-04-18"),
(8,79,"incoming","2021-02-07"),
(7,675,"outgoing","2021-05-02");
INSERT INTO `transactions` (`account_ID`,`transaction_value`,`transaction_type`,`transaction_date`)
VALUES
(4,500,"outgoing","2021-03-05"), #91
(2,542,"outgoing","2021-03-10"),
(7,384,"incoming","2021-12-31"),
(2,325,"incoming","2021-10-19"),
(3,413,"outgoing","2021-08-06"),
(8,73,"outgoing","2021-04-08"),
(9,510,"incoming","2022-02-23"),
(3,950,"outgoing","2021-05-17"),
(6,503,"incoming","2021-01-26"),
(9,154,"incoming","2021-08-29");
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (1, 300, 21, "2021-02-05", 5);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (4, 500, 12, "2021-03-21", 21);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (5, 470, 15, "2021-09-19", 19);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (7, 200, 25, "2021-10-15", 15);
INSERT INTO loans (account_ID, payment_rate, loan_length, first_payment_date, monthly_due_date) VALUES (9, 150, 29, "2021-11-07", 7);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 8);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 57);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 75);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 86);
INSERT INTO loan_transactions (loan_ID, transaction_ID) VALUES (1, 91);
我正在尝试执行的查询:
SELECT accounts.account_number, customers.first_name, customers.last_name, loans.monthly_due_date
FROM customer_accounts
INNER JOIN customers ON customers.customer_ID = customer_accounts.customer_ID
INNER JOIN accounts ON accounts.account_ID = customer_accounts.account_ID
INNER JOIN loans ON loans.account_ID = accounts.account_ID
WHERE loans.monthly_due_date <=7
我试过重新安装,使用不同的版本,我禁用了 UAC,我在另一台机器上测试了我的代码,它可以工作,但在我的电脑上不行,碰巧我尝试用多个 table。我试过删除缓存并使用不同的浏览器。
这看起来像是 phpmyadmin 中的错误: https://github.com/phpmyadmin/phpmyadmin/issues/17001
里程碑是 5.1.2 得到更正,它在 11 天前发布(截至此答案)。试试 phpmyadmin 5.1.2,我相信它应该得到纠正。