形成复杂的SQL语句(Forming a complex SQL statement)
我正忙着为我的一个项目构建一个有效的SQL语句。 首先,我有一个“问题”表和一个“响应”表。 响应表通过名为“question_id”的外部ID(与问题“id”相关联)与问题表相关联。 一个问题不一定得有回应,但我能提出的唯一可行的陈述只会提出一个有回应的问题,但我需要它来表明每个问题是否有回应。
那个SQL语句是:
SELECT u.firstname, q.question, r.tutor_id, r.response FROM response r JOIN question q ON q.id = r.question_id JOIN user u ON u.id = q.user_id
我的另一个问题是我也试图拉出导师的名字,但只能拉“tutor_id”,所以任何帮助都会很棒。 如果有人有任何提示,我会很感激!
适用于:
SELECT u.firstname, q.question, v.firstname, r.response FROM question q INNER JOIN user u ON u.id = q.user_di LEFT JOIN response r ON q.id = r.question_id LEFT JOIN user v ON v.id = r.tutor_id
I'm coming up stumped on forming a working SQL statement for a project of mine. First of all, I have a "questions" table and a "response" table. The response table is tied to the question table through a foreign id called "question_id" (tied to the questions "id"). A question doesn't necessarily have to have a response, but the only working statement I can come up with will only pull a question that has a response, but I need it to show every question whether or not there is a response.
That SQL statement is:
SELECT u.firstname, q.question, r.tutor_id, r.response FROM response r JOIN question q ON q.id = r.question_id JOIN user u ON u.id = q.user_id
My other problem is that I'm also trying to pull the firstname of the tutor, but can only pull the "tutor_id", so any help with that would also be awesome. If anyone has any tips, I'd appreciate it!
Works with:
SELECT u.firstname, q.question, v.firstname, r.response FROM question q INNER JOIN user u ON u.id = q.user_di LEFT JOIN response r ON q.id = r.question_id LEFT JOIN user v ON v.id = r.tutor_id
原文:https://stackoverflow.com/questions/3315130
最满意答案
您的测试没有失败的原因是您的onComplete块正在与您的实际测试方法不同的线程中运行。 考虑这个测试:
class MyTest extends FlatSpec { it should "get a List" in { def fs: List[Future[Int]] = List(Future(1)) println("Test thread " + Thread.currentThread().getName) val f: Future[List[Int]] = Future.sequence(fs) f onComplete { case x => { println("Complete thread " + Thread.currentThread().getName) assert(x.get == List(5)) }} Await.ready(f, Duration.Inf) } }
运行时,我们得到此输出,测试不会失败:
Test thread: ScalaTest-run-running-MyTest Complete thread: ForkJoinPool-1-worker-11
您希望断言与测试位于同一个线程中。 最终我认为你在onComplete之外寻找这样的东西:
assert(Await.result(f, 5 seconds) == List(1, 2, 3))
The reason your test isn't failing is that your onComplete block is being run in a separate thread from your actual test method. Consider this test:
class MyTest extends FlatSpec { it should "get a List" in { def fs: List[Future[Int]] = List(Future(1)) println("Test thread " + Thread.currentThread().getName) val f: Future[List[Int]] = Future.sequence(fs) f onComplete { case x => { println("Complete thread " + Thread.currentThread().getName) assert(x.get == List(5)) }} Await.ready(f, Duration.Inf) } }
When run we get this output and the test doesn't fail:
Test thread: ScalaTest-run-running-MyTest Complete thread: ForkJoinPool-1-worker-11
You want your assertion to be in the same thread as your test. Ultimately I think you're looking for something like this outside of your onComplete:
assert(Await.result(f, 5 seconds) == List(1, 2, 3))
相关问答
更多-
尝试使用TestContext.WriteLine()它在测试结果中输出文本。 例: [TestClass] public class UnitTest1 { private TestContext testContextInstance; ///
/// Gets or sets the test context which provides /// information about and ... -
您的测试没有失败的原因是您的onComplete块正在与您的实际测试方法不同的线程中运行。 考虑这个测试: class MyTest extends FlatSpec { it should "get a List" in { def fs: List[Future[Int]] = List(Future(1)) println("Test thread " + Thread.currentThread().getName) val f: Futu ...
-
我如何等待NSOperationQueue完成单元测试?(How do I wait until an NSOperationQueue has finished in a Unit Test?)[2022-08-04]
解决方案 我意识到我的代码是在一个永恒的循环中,因为我在主线程上调用mergeChangesFromContextDidSaveNotification ,同时还等待队列在主线程上完成。 由于在waitUntilAllOperationsAreFinished之后调用了合并更改,因此它从未执行过。 我认为答案是改变我从哪里运行NSOperationQueues。 我不应该运行一个NSOperationQueue来处理主线程上的核心数据。 我不应该出于性能原因在主线程上运行这些密集的东西,无论如何我猜。 Th ... -
IntelliJ单元测试问题(IntelliJ Unit Test issues)[2022-11-23]
从谷歌代码上的一个旧问题 : 尝试添加org.javassist javassist 3.18.1-GA org.javassist 我在同一条路上。 我相信如果你查看那个脚本,它会转过来调用这个脚本: ${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests 这是用于运行单元测试的脚本。 现在,在Xcode 5中,它只是告诉您删除Xcode 4自动创建的Run Script构建阶段。 如果你从Xcode 5运行RunUnitTests ,它只是说: RunUnitTests已过时。 要为目标运行单元测试,请使用Xcode IDE中的Test scheme操作和xcodebuild中的测试操作。 您可以从单元测 ...使用gtest进行单元测试1.6:如何查看打印出来的内容?(unit test using gtest 1.6 : how to check what is printed out?)[2022-05-12]
您必须更改功能才能使其可测试。 最简单的方法是将ostream(cout继承)传递给函数,并在单元测试中使用字符串流(也继承ostream)。 void printFoo( std::ostream &os ) { os << "Successful" << endl; } TEST(test_printFoo, printFoo) { std::ostringstream output; printFoo( output ); // Not that familiar with ...当我运行我的测试gradle测试时,我只是看到这样的消息:[...] 默认情况下,您还会看到(输出中的更深层次): 哪种测试方法失败 异常类型 发生异常的源文件和行号 要查看更多信息,请配置Test#testLogging 。 例如: tasks.withType(Test) { testLogging { exceptionFormat "full" } } 有关更多详细信息,请查看Gradle Build Language Reference中的Test 。 然后我必须 ...生成从单元测试执行开始(Build starts on Unit Test Execution)[2023-04-12]
根据评论 - 升级到最终更新2似乎解决了这个问题。 As per the comment -- upgrading to the final Update 2 seems to solve the issue.单元测试中的CXF测试失败SelectChannelConnector异常(CXF test failing SelectChannelConnector exception on Unit Test)[2024-02-27]
Jetty 9.x没有org.eclipse.jetty.server.nio.SelectChannelConnector 。 该课程来自很久以前的Jetty 8(及更早版本),现在已经EOL(生命终结) 迁移到HTTP / 2和Servlet 3.1彻底改变了Jetty中的整个连接器架构。 Apache CXF 3.1.4(非红帽版本)支持Jetty 9.2.11。 您的依赖关系树中还有3个不同版本的Jetty。 [INFO] +- org.eclipse.jetty:jetty-server:jar: ...rails 3单元测试未运行(rails 3 unit test not running)[2022-01-13]
尝试将方法定义更改为def test_better_be_true 。 Try changing your method definition to def test_better_be_true.相关文章
更多- JDBC系列教程之四:SQL注入PreparedStatement和Statement
- sql问题
- Mybatis SQL 语句构建器
- 如何优化这个sql语句
- 不会sql语句....谁帮我优化下
- sql 语句
- 一个sql查询
- 关于mysql 的 sql
- sql语句-关于行列互换等问题的查询语句
- 请教一个SQL实现
最新问答
更多- 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
- linux的常用命令干什么用的
- 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
- 如何交换返回集中的行?(How to swap rows in a return set?)
- 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
- 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
- Java中的不可变类(Immutable class in Java)
- WordPress发布查询(WordPress post query)
- 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
- 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
- GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
- 绑定属性设置器未被调用(Bound Property Setter not getting Called)
- linux ubuntu14.04版没有那个文件或目录
- 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
- 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
- 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
- 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
- ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
- linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
- Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
- 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
- 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
- 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
- Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
- 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
- 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
- 如何按部门显示报告(How to display a report by Department wise)
- Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
- Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
- WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)