找到 4219 篇文章 关于 MySQLi
588 次浏览
要按升序选择最后三行,请使用 ORDER BY DESC LIMIT,如下面的语法所示:select * from (select * from yourTableName order by yourColumnName desc limit 3) anyAliasName order by yourColumnName ;让我们先创建一个表:mysql> create table DemoTable1579 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1579(Name) values('Robert'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable1579(Name) values('Bob'); Query OK, 1 ... 阅读更多
324 次浏览
以下是创建第一个表的查询。mysql> create table DemoTable1 -> ( -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.67 sec)为了理解上述概念,让我们创建第二个表。mysql> create table DemoTable2 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2 values('Chris'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录:mysql> select * from DemoTable2;这将产生以下输出:+-------+ ... 阅读更多
160 次浏览
获取行数最简单的方法是使用聚合函数 COUNT(*)。让我们先创建一个表:mysql> create table DemoTable1575 -> ( -> FirstName varchar(20) -> ); Query OK, 0 rows affected (1.00 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1575 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1575 values('Robert'); Query OK, 1 row affected (0.15 sec)显示表中的所有记录 ... 阅读更多
848 次浏览
让我们先创建一个表:mysql> create table DemoTable1574 -> ( -> StudentCode varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1574 values('111_Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1574 values('David_12345'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录:mysql> select * from DemoTable1574;这将产生以下 ... 阅读更多
283 次浏览
要在 MySQL 中检索数据库中的表名,语法如下:show tables from yourDatabaseName;让我们实现上述查询,以便在 MySQL 中检索数据库中的表名:mysql> show tables from hb_student_tracker;这将产生以下输出:+------------------------------+ | Tables_in_hb_student_tracker | +------------------------------+ | demotable192 | | demotable193 | | demotable194 | | demotable195 | | demotable196 ... 阅读更多
112 次浏览
让我们先创建一个表:mysql> create table DemoTable1572 -> ( -> StudentId int, -> StudentMarks int, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.56 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1572 values(1, 79, 'Sam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1572 values(2, 89, 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1572 values(3, 98, 'David'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1572 values(4, 79, 'Bob'); Query OK, 1 row affected (0.10 sec)显示 ... 阅读更多
1K+ 次浏览
要将 IF 语句插入 MySQL 查询,请使用以下语法:select yourColumnName ,if(yourCondition, yourStatement1, yourStatement2) from yourTableName;让我们先创建一个表:mysql> create table DemoTable1571 -> ( -> Id int, -> Value int -> ); Query OK, 0 rows affected (5.63 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1571 values(101, 500); Query OK, 1 row affected (1.07 sec) mysql> insert into DemoTable1571 values(102, 450); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable1571 values(103, 300); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1571 ... 阅读更多
399 次浏览
您需要在 URL 中使用端口号 3306。语法如下:jdbc:mysql://127.0.0.1:3306示例import java.sql.Connection; import java.sql.DriverManager; public class MySQLConnectionToJava { public static void main(String[] args) { String JDBCURL="jdbc:mysql://127.0.0.1:3306/sample?useSSL=false"; Connection con=null; try { con = DriverManager.getConnection(JDBCURL,"root","123456"); if(con!=null) { System.out.println("MySQL 连接成功,端口号为 3306。"); } } catch(Exception e) { e.printStackTrace(); } } }输出MySQL 连接成功,端口号为 3306。
231 次浏览
让我们先创建一个表:mysql> create table DemoTable1570 -> ( -> ArrivalTime datetime -> ); Query OK, 0 rows affected (0.87 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1570 values('2019-10-15 5:10:00'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1570 values('2019-10-15 23:00:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1570 values('2019-10-15 23:10:00'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1570 values('2019-10-15 16:10:00'); Query OK, 1 row affected (0.15 sec)显示表中的所有记录使用 select 语句:mysql> select * from DemoTable1570;这 ... 阅读更多
3K+ 次浏览
让我们先创建一个表:mysql> create table DemoTable1569 -> ( -> StudentId varchar(10), -> StudentName varchar(20) -> ); Query OK, 0 rows affected (3.05 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1569 values('John_12', 'John Smith'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1569 values('David_321', 'Carol Taylor'); Query OK, 1 row affected (0.50 sec) mysql> insert into DemoTable1569 values('David_989', 'David Miller'); Query OK, 1 row affected (0.24 sec)显示表中的所有记录使用 select 语句:mysql> select * from DemoTable1569;这将产生以下输出+-----------+--------------+ | ... 阅读更多