Access the php file installed on the network server from Android,
Execute the SQL statement against MySQL running in the server from the php file.
The content of the question is the SQL statement part, and if there is no corresponding data in the specified column, only that part will contain null
I would like to obtain the results, but I couldn't find the relevant description.
test table + -------- + ------- + ------- + | a | b | c | + -------- + ------- + ------- + | 1 | AAA | WWW | | 2 | BBB | YYY | | 3 | CCC | ZZZ | + -------- + ------- + ------- +
SELECT a, b FROM test WHERE c = 'WWW'; SELECT a, b FROM test WHERE c = 'XXX'; SELECT a, b FROM test WHERE c = 'ZZZ';
I want this answer. + -------- + ------- + | a | b | + -------- + ------- + | 1 | AAA | | null | null | | 3 | CCC | + -------- + ------- +
Isn't it possible to obtain the above result by modifying SQL statements?
Answer # 1
LEFT JOINthe same table, you can get the result.
The response may be terrible, but ...
select t2.a, t2.b from test t1 left join test t2 on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c and t1.c in ('WWW', 'XXX', 'ZZZ') order by t1.a;
Answer # 2
SELECT CASE WHEN c = 'WWW' or c = 'ZZZ' THEN a ELSE null end as a, CASE WHEN c = 'WWW' or c = 'ZZZ' THEN b ELSE null end as b FROM DatabaseName.TableName;
Answer # 3
A is like a key, so it shouldn't be null?
select a, case when c in ('WWW', 'XXX', 'ZZZ') then b end as b from test table order by a
Answer # 4
If you use the character group of the Where clause as a reference, how about putting it into the from clause and LEFT JOIN it?
select test.a, test.b from ( select 'WWW' as a_keyword, 1 as sort_no union select 'XXX', 2 union select 'ZZZ', 3 ) as t1 left join test on t1.a_keyword = test.c order by t1.sort_no ;
I think this handwriting will be troublesome, so I think that text will be generated with some tools.
- php - when reading a text column with select with mysql, characters are cut off in the middle
- mysql - i want to total the data extracted by select
- mysql - select * from contents are not displayed even if the table name is displayed
- mysql - error occurs when executing migrate in laravel/vue heroku
- how to use mysql select case
- mysql - i want to execute a sql statement that does update if there is existing data, or insert if there is
- error when executing "php artisan migrate" in laravel on aws ec2 and rds (mysql) environment on aws
- mysql study notes full use examples of select statements
- java - i want to select data with the select statement of mysql and display it on the browser
- php - if there is data in the db table with mysql, please tell me how to insert if there is no update
- executing "pip install mysql-python" with python3 gives error
- MySQL select, insert, update batch operation statement code example
- mysql - count after sql select
- Python select a number from the list list and its corresponding coordinate method
- Simple understanding of MySQL SELECT execution order
- MySQL transaction select for update and data consistency processing explained
- java - if there is no corresponding item in the search, i want to reflect the character string immediately tu
- mysql - if there is no sql value, i want to fill it with an earlier value
- i want to retrieve the value with select * (with mysqli and bind)
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- python - importerror: cannot import name md5 error cannot be resolved