我需要在单个mysql站点中合并两个JOIN条件

时间:2019-04-19 18:55:58

标签: mysql

我有以下两个表:C:\Users\itzThiefz.exe\AndroidStudioProjects\RavenNetwork>gradlew lintdebug > Configure project :app registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) > Task :app:processDebugGoogleServices Parsing json file: C:\Users\itzThiefz.exe\AndroidStudioProjects\RavenNetwork\app\google-services.json > Task :app:lintDebug Wrote HTML report to file:///C:/Users/itzThiefz.exe/AndroidStudioProjects/RavenNetwork/app/build/reports/lint-results-debug.html Wrote XML report to file:///C:/Users/itzThiefz.exe/AndroidStudioProjects/RavenNetwork/app/build/reports/lint-results-debug.xml > Task :app:lintDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:lintDebug'. > Lint found errors in the project; aborting build. Fix the issues identified by lint, or add the following to your build script to proceed with errors: ... android { lintOptions { abortOnError false } } ... Errors found: C:\Users\itzThiefz.exe\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-core\1.16.1\8a938ece0ad8d8bf77d790c502ba51ebec114aa9\grpc-core-1.16.1.jar: Error: Invalid package reference in li brary; not included in Android: javax.naming.directory. Referenced from io.grpc.internal.JndiResourceResolverFactory.JndiResourceResolver. [InvalidPackage] C:\Users\itzThiefz.exe\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-core\1.16.1\8a938ece0ad8d8bf77d790c502ba51ebec114aa9\grpc-core-1.16.1.jar: Error: Invalid package reference in li brary; not included in Android: javax.naming. Referenced from io.grpc.internal.JndiResourceResolverFactory.JndiResourceResolver. [InvalidPackage] * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 30s 15 actionable tasks: 2 executed, 13 up-to-date destinations。 目的地有2个字段:ID和NAME 价格包含4个字段:ID_FROM(目的地的ID),ID_TO(目的地的ID),PERSONS,PRICE

我需要做一条SQL语句,将ID_FROM更改为对应的NAME,将ID_to更改为相同的内容。

在SQL语句中使用JOIN一次只能执行一次,但是我需要以某种方式组合并在同一条语句中获得两个NAMES

这单独起作用:

prices
SELECT     b.name
FROM       dm_prices a
INNER JOIN dm_destinations b
ON         a.from_id = b.id

但是我需要将两者合并到一个查询中

1 个答案:

答案 0 :(得分:1)

将表destinationsdm_prices的表加入两次:

select
  df.name name_from,
  dt.name name_to
from dm_prices p
inner join dm_destinations df on df.id = p.id_from
inner join dm_destinations dt on dt.id = p.id_to

如果存在id_fromid_to列中任一列为null的情况,则使用inner join代替left join