From d1c04d622129fcfde13a6c8de763516bb575caaf Mon Sep 17 00:00:00 2001 From: Lion <756433556@qq.com> Date: Tue, 23 Jun 2020 09:38:52 +0800 Subject: [PATCH 1/5] select practice --- src/main/java/com/github/hcsp/sql/Sql.java | 60 ++++++++++++++++++---- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/hcsp/sql/Sql.java b/src/main/java/com/github/hcsp/sql/Sql.java index 418a0df..cb5fe61 100644 --- a/src/main/java/com/github/hcsp/sql/Sql.java +++ b/src/main/java/com/github/hcsp/sql/Sql.java @@ -2,9 +2,8 @@ package com.github.hcsp.sql; import java.io.File; import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; +import java.sql.*; +import java.util.ArrayList; import java.util.List; public class Sql { @@ -57,7 +56,9 @@ public class Sql { // 用户信息 public static class User { - Integer id; + + public static Integer id; + String name; String tel; String address; @@ -82,14 +83,21 @@ public String toString() { // | 2 | // +-----+ public static int countUsersWhoHaveBoughtGoods(Connection databaseConnection, Integer goodsId) throws SQLException { - return 0; + String sql = "select count(distinct USER_ID) from 'ORDER' where GOODS_ID = ?"; + try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { + statement.setInt(1, goodsId); + ResultSet resultSet = statement.executeQuery(); + return resultSet.next() ? resultSet.getInt(1) : 1; + } + + } /** * 题目2: * 分页查询所有用户,按照ID倒序排列 * - * @param pageNum 第几页,从1开始 + * @param pageNum 第几页,从1开始 * @param pageSize 每页有多少个元素 * @return 指定页中的用户 */ @@ -100,7 +108,23 @@ public static int countUsersWhoHaveBoughtGoods(Connection databaseConnection, In // | 1 | zhangsan | tel1 | beijing | // +----+----------+------+----------+ public static List getUsersByPageOrderedByIdDesc(Connection databaseConnection, int pageNum, int pageSize) throws SQLException { - return null; + String sql = "select * from USER order by ID desclimit ?offset"; + List list = new ArrayList<>(); + try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { + statement.setInt(1, (pageNum - 1) * pageSize); + statement.setInt(2, pageSize); + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + User user = new User(); + User.id = resultSet.getInt(1); + user.name = resultSet.getString(2); + user.tel = resultSet.getString(3); + user.address = resultSet.getString(4); + list.add(user); + } + } + return list; + } // 商品及其营收 @@ -176,6 +200,7 @@ public static List getInnerJoinOrders(Connection databaseConnection) thro /** * 题目5: * 查询所有订单信息,哪怕它的用户名、商品名缺失,即LEFT JOIN方式 + * @return */ // 预期的结果为: // +----------+-----------+------------+-------------+ @@ -197,10 +222,27 @@ public static List getInnerJoinOrders(Connection databaseConnection) thro // +----------+-----------+------------+-------------+ // | 8 | NULL | NULL | 60 | // +----------+-----------+------------+-------------+ - public static List getLeftJoinOrders(Connection databaseConnection) throws SQLException { - return null; + public static List getLeftJoinOrders(Connection databaseConnection) throws SQLException { + String sql = "select GOODS_ID, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as GMV\n" + + "from `ORDER`\n" + + " join GOODS ON `ORDER`.GOODS_ID = GOODS.ID\n" + + "group by GOODS_ID\n" + + "order by GMV desc"; + List list = new ArrayList<>(); + try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + GoodsAndGmv goodsAndGmv = new GoodsAndGmv(); + goodsAndGmv.goodsId = resultSet.getInt(1); + goodsAndGmv.goodsName = resultSet.getString(2); + goodsAndGmv.gmv = resultSet.getBigDecimal(3); + list.add(goodsAndGmv); + } + } + return list; } + // 注意,运行这个方法之前,请先运行mvn initialize把测试数据灌入数据库 public static void main(String[] args) throws SQLException { File projectDir = new File(System.getProperty("basedir", System.getProperty("user.dir"))); From 01920966e554e40daeda16cf5cb6c77d2e774746 Mon Sep 17 00:00:00 2001 From: Lion <756433556@qq.com> Date: Tue, 23 Jun 2020 13:40:40 +0800 Subject: [PATCH 2/5] Select --- src/main/java/com/github/hcsp/sql/Sql.java | 75 +++++++++++++++------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/hcsp/sql/Sql.java b/src/main/java/com/github/hcsp/sql/Sql.java index cb5fe61..a9ec4f0 100644 --- a/src/main/java/com/github/hcsp/sql/Sql.java +++ b/src/main/java/com/github/hcsp/sql/Sql.java @@ -156,8 +156,25 @@ public String toString() { // | 3 | goods3 | 20 | // +----+--------+------+ public static List getGoodsAndGmv(Connection databaseConnection) throws SQLException { - return null; - } + String sql = "select GOODS_ID, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as GMV\n" + + "from `ORDER`\n" + + " join GOODS ON `ORDER`.GOODS_ID = GOODS.ID\n" + + "group by GOODS_ID\n" + + "order by GMV desc"; + List list = new ArrayList<>(); + try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + GoodsAndGmv goodsAndGmv = new GoodsAndGmv(); + goodsAndGmv.goodsId = resultSet.getInt(1); + goodsAndGmv.goodsName = resultSet.getString(2); + goodsAndGmv.gmv = resultSet.getBigDecimal(3); + list.add(goodsAndGmv); + } + } + return list; + } } + // 订单详细信息 @@ -194,7 +211,13 @@ public String toString() { // | 6 | zhangsan | goods3 | 20 | // +----------+-----------+------------+-------------+ public static List getInnerJoinOrders(Connection databaseConnection) throws SQLException { - return null; + String sql = "select `ORDER`.ID, USER.NAME, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as TOTAL_PRICE\n" + + "from `ORDER`\n" + + " join GOODS on `ORDER`.GOODS_ID = GOODS.ID\n" + + " join USER on `ORDER`.USER_ID = USER.ID\n" + + "group by \"ORDER\".ID"; + return order2List(databaseConnection, sql); + } /** @@ -222,24 +245,13 @@ public static List getInnerJoinOrders(Connection databaseConnection) thro // +----------+-----------+------------+-------------+ // | 8 | NULL | NULL | 60 | // +----------+-----------+------------+-------------+ - public static List getLeftJoinOrders(Connection databaseConnection) throws SQLException { - String sql = "select GOODS_ID, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as GMV\n" + + public static List getLeftJoinOrders(Connection databaseConnection) throws SQLException { + String sql = "select `ORDER`.ID, USER.NAME, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as TOTAL_PRICE\n" + "from `ORDER`\n" + - " join GOODS ON `ORDER`.GOODS_ID = GOODS.ID\n" + - "group by GOODS_ID\n" + - "order by GMV desc"; - List list = new ArrayList<>(); - try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { - ResultSet resultSet = statement.executeQuery(); - while (resultSet.next()) { - GoodsAndGmv goodsAndGmv = new GoodsAndGmv(); - goodsAndGmv.goodsId = resultSet.getInt(1); - goodsAndGmv.goodsName = resultSet.getString(2); - goodsAndGmv.gmv = resultSet.getBigDecimal(3); - list.add(goodsAndGmv); - } - } - return list; + " left join GOODS on `ORDER`.GOODS_ID = GOODS.ID\n" + + " left join USER on `ORDER`.USER_ID = USER.ID\n" + + "group by \"ORDER\".ID"; + return order2List(databaseConnection, sql); } @@ -248,12 +260,27 @@ public static void main(String[] args) throws SQLException { File projectDir = new File(System.getProperty("basedir", System.getProperty("user.dir"))); String jdbcUrl = "jdbc:h2:file:" + new File(projectDir, "target/test").getAbsolutePath(); try (Connection connection = DriverManager.getConnection(jdbcUrl, "root", "Jxi1Oxc92qSj")) { - System.out.println(countUsersWhoHaveBoughtGoods(connection, 1)); - System.out.println(getUsersByPageOrderedByIdDesc(connection, 2, 3)); - System.out.println(getGoodsAndGmv(connection)); + System.out.println(Sql.countUsersWhoHaveBoughtGoods(connection, 1)); + System.out.println(Sql.getUsersByPageOrderedByIdDesc(connection, 2, 3)); + System.out.println(Sql.getGoodsAndGmv(connection)); System.out.println(getInnerJoinOrders(connection)); System.out.println(getLeftJoinOrders(connection)); } } + public static List order2List(Connection databaseConnection, String sql) throws SQLException { + List list = new ArrayList<>(); + try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + Order order = new Order(); + order.id = resultSet.getInt(1); + order.userName = resultSet.getString(2); + order.goodsName = resultSet.getString(3); + order.totalPrice = resultSet.getBigDecimal(4); + list.add(order); + } + } + return list; + } + } -} From 8228336d6bfae340c28400f19f53ffa91de3619d Mon Sep 17 00:00:00 2001 From: Lion <756433556@qq.com> Date: Tue, 23 Jun 2020 13:58:14 +0800 Subject: [PATCH 3/5] Select --- src/main/java/com/github/hcsp/sql/Sql.java | 232 ++++++++++++--------- 1 file changed, 129 insertions(+), 103 deletions(-) diff --git a/src/main/java/com/github/hcsp/sql/Sql.java b/src/main/java/com/github/hcsp/sql/Sql.java index a9ec4f0..43518d6 100644 --- a/src/main/java/com/github/hcsp/sql/Sql.java +++ b/src/main/java/com/github/hcsp/sql/Sql.java @@ -83,12 +83,14 @@ public String toString() { // | 2 | // +-----+ public static int countUsersWhoHaveBoughtGoods(Connection databaseConnection, Integer goodsId) throws SQLException { - String sql = "select count(distinct USER_ID) from 'ORDER' where GOODS_ID = ?"; - try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { + try (PreparedStatement statement = databaseConnection.prepareStatement("select count(distinct user_id) from `order` where GOODS_ID = ?")) { statement.setInt(1, goodsId); ResultSet resultSet = statement.executeQuery(); - return resultSet.next() ? resultSet.getInt(1) : 1; + while (resultSet.next()) { + return resultSet.getInt(1); + } } + return 0; } @@ -108,41 +110,43 @@ public static int countUsersWhoHaveBoughtGoods(Connection databaseConnection, In // | 1 | zhangsan | tel1 | beijing | // +----+----------+------+----------+ public static List getUsersByPageOrderedByIdDesc(Connection databaseConnection, int pageNum, int pageSize) throws SQLException { - String sql = "select * from USER order by ID desclimit ?offset"; - List list = new ArrayList<>(); - try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { - statement.setInt(1, (pageNum - 1) * pageSize); + List users = new ArrayList<>(); + try (PreparedStatement statement = databaseConnection.prepareStatement("select * from user order by id desc limit (?-1)*?,?")) { + statement.setInt(1, pageNum); statement.setInt(2, pageSize); + statement.setInt(3, pageSize); ResultSet resultSet = statement.executeQuery(); + users = new ArrayList<>(); while (resultSet.next()) { User user = new User(); - User.id = resultSet.getInt(1); - user.name = resultSet.getString(2); + user.id = resultSet.getInt(1); + user.name = resultSet.getNString(2); user.tel = resultSet.getString(3); - user.address = resultSet.getString(4); - list.add(user); + user.address = resultSet.getNString(4); + + users.add(user); } } - return list; + return users; - } + } - // 商品及其营收 - public static class GoodsAndGmv { - Integer goodsId; // 商品ID - String goodsName; // 商品名 - BigDecimal gmv; // 商品的所有销售额 + // 商品及其营收 + public static class GoodsAndGmv { + Integer goodsId; // 商品ID + String goodsName; // 商品名 + BigDecimal gmv; // 商品的所有销售额 - @Override - public String toString() { - return "GoodsAndGmv{" + "goodsId=" + goodsId + ", goodsName='" + goodsName + '\'' + ", gmv=" + gmv + '}'; + @Override + public String toString() { + return "GoodsAndGmv{" + "goodsId=" + goodsId + ", goodsName='" + goodsName + '\'' + ", gmv=" + gmv + '}'; + } } - } - /** - * 题目3: - * 查询所有的商品及其销售额,按照销售额从大到小排序 - */ + /** + * 题目3: + * 查询所有的商品及其销售额,按照销售额从大到小排序 + */ // 预期的结果应该如图所示 // +----+--------+------+ // | ID | NAME | GMV | @@ -155,45 +159,45 @@ public String toString() { // +----+--------+------+ // | 3 | goods3 | 20 | // +----+--------+------+ - public static List getGoodsAndGmv(Connection databaseConnection) throws SQLException { - String sql = "select GOODS_ID, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as GMV\n" + - "from `ORDER`\n" + - " join GOODS ON `ORDER`.GOODS_ID = GOODS.ID\n" + - "group by GOODS_ID\n" + - "order by GMV desc"; - List list = new ArrayList<>(); - try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { - ResultSet resultSet = statement.executeQuery(); - while (resultSet.next()) { - GoodsAndGmv goodsAndGmv = new GoodsAndGmv(); - goodsAndGmv.goodsId = resultSet.getInt(1); - goodsAndGmv.goodsName = resultSet.getString(2); - goodsAndGmv.gmv = resultSet.getBigDecimal(3); - list.add(goodsAndGmv); + public static List getGoodsAndGmv (Connection databaseConnection) throws SQLException { + List gmvList = new ArrayList<>(); + + try (PreparedStatement statement = databaseConnection.prepareStatement("select `order`.goods_id, goods.name, `order`.goods_price * sum(`order`.goods_num) as gmv from `order`\n" + + "join goods\n" + + "on `order`.goods_id = goods.id\n" + + "group by `order`.goods_id\n" + + "order by gmv desc")) { + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + GoodsAndGmv goodsAndGmv = new GoodsAndGmv(); + goodsAndGmv.goodsId = resultSet.getInt(1); + goodsAndGmv.goodsName = resultSet.getString(2); + goodsAndGmv.gmv = resultSet.getBigDecimal(3); + gmvList.add(goodsAndGmv); + } } - } - return list; - } } + return gmvList; + } - // 订单详细信息 - public static class Order { - Integer id; // 订单ID - String userName; // 用户名 - String goodsName; // 商品名 - BigDecimal totalPrice; // 订单总金额 + // 订单详细信息 + public static class Order { + Integer id; // 订单ID + String userName; // 用户名 + String goodsName; // 商品名 + BigDecimal totalPrice; // 订单总金额 - @Override - public String toString() { - return "Order{" + "id=" + id + ", userName='" + userName + '\'' + ", goodsName='" + goodsName + '\'' + ", totalPrice=" + totalPrice + '}'; + @Override + public String toString() { + return "Order{" + "id=" + id + ", userName='" + userName + '\'' + ", goodsName='" + goodsName + '\'' + ", totalPrice=" + totalPrice + '}'; + } } - } - /** - * 题目4: - * 查询订单信息,只查询用户名、商品名齐全的订单,即INNER JOIN方式 - */ + /** + * 题目4: + * 查询订单信息,只查询用户名、商品名齐全的订单,即INNER JOIN方式 + */ // 预期的结果为: // +----------+-----------+------------+-------------+ // | ORDER_ID | USER_NAME | GOODS_NAME | TOTAL_PRICE | @@ -210,21 +214,34 @@ public String toString() { // +----------+-----------+------------+-------------+ // | 6 | zhangsan | goods3 | 20 | // +----------+-----------+------------+-------------+ - public static List getInnerJoinOrders(Connection databaseConnection) throws SQLException { - String sql = "select `ORDER`.ID, USER.NAME, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as TOTAL_PRICE\n" + - "from `ORDER`\n" + - " join GOODS on `ORDER`.GOODS_ID = GOODS.ID\n" + - " join USER on `ORDER`.USER_ID = USER.ID\n" + - "group by \"ORDER\".ID"; - return order2List(databaseConnection, sql); + public static List getInnerJoinOrders (Connection databaseConnection) throws SQLException { + List orders = new ArrayList<>(); - } + try (PreparedStatement statement = databaseConnection.prepareStatement("select `order`.id as order_id, user.name as user_name, goods.name as goods_name, `order`.goods_price * sum(`order`.goods_num) as total_price from `order`\n" + + "join goods\n" + + "\ton `order`.goods_id = goods.id\n" + + "join user\n" + + "\ton `order`.user_id = user.id\n" + + "group by `order`.id")) { + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + Order order = new Order(); + order.id = resultSet.getInt(1); + order.userName = resultSet.getString(2); + order.goodsName = resultSet.getString(3); + order.totalPrice = resultSet.getBigDecimal(4); + orders.add(order); + } + } + return orders; - /** - * 题目5: - * 查询所有订单信息,哪怕它的用户名、商品名缺失,即LEFT JOIN方式 - * @return - */ + } + + /** + * 题目5: + * 查询所有订单信息,哪怕它的用户名、商品名缺失,即LEFT JOIN方式 + * @return + */ // 预期的结果为: // +----------+-----------+------------+-------------+ // | ORDER_ID | USER_NAME | GOODS_NAME | TOTAL_PRICE | @@ -245,42 +262,51 @@ public static List getInnerJoinOrders(Connection databaseConnection) thro // +----------+-----------+------------+-------------+ // | 8 | NULL | NULL | 60 | // +----------+-----------+------------+-------------+ - public static List getLeftJoinOrders(Connection databaseConnection) throws SQLException { - String sql = "select `ORDER`.ID, USER.NAME, GOODS.NAME, sum(GOODS_NUM * GOODS_PRICE) as TOTAL_PRICE\n" + - "from `ORDER`\n" + - " left join GOODS on `ORDER`.GOODS_ID = GOODS.ID\n" + - " left join USER on `ORDER`.USER_ID = USER.ID\n" + - "group by \"ORDER\".ID"; - return order2List(databaseConnection, sql); - } + public static List getLeftJoinOrders (Connection databaseConnection) throws SQLException { + List orders = new ArrayList<>(); + + try (PreparedStatement statement = databaseConnection.prepareStatement("select `order`.id AS ORDER_ID, \n" + + "\t\tuser.name AS USER_NAME, \n" + + "\t\tgoods.name AS GOODS_NAME, \n" + + "\t\t`order`.goods_price * sum(`order`.goods_num) AS total_price \n" + + "from `order`\n" + + "\tleft join goods\n" + + "\t\ton `order`.goods_id = goods.id\n" + + "\tleft join user\n" + + "\t\ton `order`.user_id = user.id\n" + + "group by `order`.id")) { + ResultSet resultSet = statement.executeQuery(); + while (resultSet.next()) { + Order order = new Order(); + order.id = resultSet.getInt(1); + order.userName = resultSet.getString(2); + order.goodsName = resultSet.getString(3); + order.totalPrice = resultSet.getBigDecimal(4); + orders.add(order); + } + } + return orders; - // 注意,运行这个方法之前,请先运行mvn initialize把测试数据灌入数据库 - public static void main(String[] args) throws SQLException { - File projectDir = new File(System.getProperty("basedir", System.getProperty("user.dir"))); - String jdbcUrl = "jdbc:h2:file:" + new File(projectDir, "target/test").getAbsolutePath(); - try (Connection connection = DriverManager.getConnection(jdbcUrl, "root", "Jxi1Oxc92qSj")) { - System.out.println(Sql.countUsersWhoHaveBoughtGoods(connection, 1)); - System.out.println(Sql.getUsersByPageOrderedByIdDesc(connection, 2, 3)); - System.out.println(Sql.getGoodsAndGmv(connection)); - System.out.println(getInnerJoinOrders(connection)); - System.out.println(getLeftJoinOrders(connection)); } - } - public static List order2List(Connection databaseConnection, String sql) throws SQLException { - List list = new ArrayList<>(); - try (PreparedStatement statement = databaseConnection.prepareStatement(sql)) { - ResultSet resultSet = statement.executeQuery(); - while (resultSet.next()) { - Order order = new Order(); - order.id = resultSet.getInt(1); - order.userName = resultSet.getString(2); - order.goodsName = resultSet.getString(3); - order.totalPrice = resultSet.getBigDecimal(4); - list.add(order); - } + // 注意,运行这个方法之前,请先运行mvn initialize把测试数据灌入数据库 + public static void main (String[]args) throws SQLException { + File projectDir = new File(System.getProperty("basedir", System.getProperty("user.dir"))); + String jdbcUrl = "jdbc:h2:file:" + new File(projectDir, "target/test").getAbsolutePath(); + try (Connection connection = DriverManager.getConnection(jdbcUrl, "root", "Jxi1Oxc92qSj")) { + System.out.println(Sql.countUsersWhoHaveBoughtGoods(connection, 1)); + System.out.println(Sql.getUsersByPageOrderedByIdDesc(connection, 2, 3)); + System.out.println(Sql.getGoodsAndGmv(connection)); + System.out.println(getInnerJoinOrders(connection)); + System.out.println(getLeftJoinOrders(connection)); } - return list; } } + + + + + + + From 9d9c924907693549515f43d29cedd7bcd1122a31 Mon Sep 17 00:00:00 2001 From: Lion <756433556@qq.com> Date: Tue, 23 Jun 2020 14:37:15 +0800 Subject: [PATCH 4/5] Select --- src/main/java/com/github/hcsp/sql/Sql.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/github/hcsp/sql/Sql.java b/src/main/java/com/github/hcsp/sql/Sql.java index 43518d6..527c61c 100644 --- a/src/main/java/com/github/hcsp/sql/Sql.java +++ b/src/main/java/com/github/hcsp/sql/Sql.java @@ -75,7 +75,9 @@ public String toString() { * * @param goodsId 指定的商品ID * @return 有多少用户买过这个商品 + * @param databaseConnection */ + // 例如,输入goodsId = 1,返回2,因为有2个用户曾经买过商品1。 // +-----+ // |count| @@ -102,6 +104,7 @@ public static int countUsersWhoHaveBoughtGoods(Connection databaseConnection, In * @param pageNum 第几页,从1开始 * @param pageSize 每页有多少个元素 * @return 指定页中的用户 + * @param databaseConnection */ // 例如,pageNum = 2, pageSize = 3(每页3个元素,取第二页),则应该返回: // +----+----------+------+----------+ @@ -146,6 +149,7 @@ public String toString() { /** * 题目3: * 查询所有的商品及其销售额,按照销售额从大到小排序 + * @param databaseConnection */ // 预期的结果应该如图所示 // +----+--------+------+ @@ -197,6 +201,7 @@ public String toString() { /** * 题目4: * 查询订单信息,只查询用户名、商品名齐全的订单,即INNER JOIN方式 + * @param databaseConnection */ // 预期的结果为: // +----------+-----------+------------+-------------+ @@ -241,6 +246,7 @@ public static List getInnerJoinOrders (Connection databaseConnection) thr * 题目5: * 查询所有订单信息,哪怕它的用户名、商品名缺失,即LEFT JOIN方式 * @return + * @param databaseConnection */ // 预期的结果为: // +----------+-----------+------------+-------------+ From c3168b8540a171f353bdfa095f31e608e15a374a Mon Sep 17 00:00:00 2001 From: Lion <756433556@qq.com> Date: Tue, 23 Jun 2020 14:51:17 +0800 Subject: [PATCH 5/5] Select --- src/main/java/com/github/hcsp/sql/Sql.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/hcsp/sql/Sql.java b/src/main/java/com/github/hcsp/sql/Sql.java index 527c61c..7425375 100644 --- a/src/main/java/com/github/hcsp/sql/Sql.java +++ b/src/main/java/com/github/hcsp/sql/Sql.java @@ -150,6 +150,7 @@ public String toString() { * 题目3: * 查询所有的商品及其销售额,按照销售额从大到小排序 * @param databaseConnection + * @return tag */ // 预期的结果应该如图所示 // +----+--------+------+ @@ -202,6 +203,7 @@ public String toString() { * 题目4: * 查询订单信息,只查询用户名、商品名齐全的订单,即INNER JOIN方式 * @param databaseConnection + * @return tag */ // 预期的结果为: // +----------+-----------+------------+-------------+ @@ -245,7 +247,7 @@ public static List getInnerJoinOrders (Connection databaseConnection) thr /** * 题目5: * 查询所有订单信息,哪怕它的用户名、商品名缺失,即LEFT JOIN方式 - * @return + * @return tag * @param databaseConnection */ // 预期的结果为: