首页 \ 问答 \ MySQL查询三个表(MySQL query for three tables)

MySQL查询三个表(MySQL query for three tables)

我有三个人表,属性和属性的潜在价值。 我无法找出一个查询来显示所有人,每个人属性及其缺失/ null属性。

这是一个示例表......

attributes
+---------------------+
| attribute_name (col)|
+---------------------+
| name                |
+---------------------+
| age                 |
+---------------------+
| gender              |
+---------------------+
| email               |
+---------------------+

people
+-----------+----------+
| person_id | value_id |
+-----------+----------+
| 2         | 7        |
+-----------+----------+
| 2         | 9        |
+-----------+----------+
| 3         | 8        |
+-----------+----------+

values
+---------------+----------------+-------+
| value_id (pk) | attribute_name | value |
+---------------+----------------+-------+
| 7             | age            | 35    |
+---------------+----------------+-------+
| 8             | age            | 28    |
+---------------+----------------+-------+
| 9             | gender         | male  |
+---------------+----------------+-------+


我如何加入这三个表来显示这样的东西?

+-----------+----------+-----------------+--------+
| person_id | value_id | attribute_name  | value  |
+-----------+----------+-----------------+--------+
| 2         | 7        | age             | 35     |
+-----------+----------+-----------------+--------+
| 2         | 9        | gender          | male   |
+-----------+----------+-----------------+--------+
| 2         | NULL     | name            | NULL   |
+-----------+----------+-----------------+--------+
| 2         | NULL     | email           | NULL   |
+-----------+----------+-----------------+--------+
| 3         | 8        | age             | 28     |
+-----------+----------+-----------------+--------+
| 3         | NULL     | gender          | NULL   |
+-----------+----------+-----------------+--------+
| 3         | NULL     | name            | NULL   |
+-----------+----------+-----------------+--------+
| 3         | NULL     | email           | NULL   |
+-----------+----------+-----------------+--------+

I have three tables with people, the attributes and potential value for the attributes. I can't figure out a query to display all the people, each persons attributes and their missing/null attributes.

Here's an example table...

attributes
+---------------------+
| attribute_name (col)|
+---------------------+
| name                |
+---------------------+
| age                 |
+---------------------+
| gender              |
+---------------------+
| email               |
+---------------------+

people
+-----------+----------+
| person_id | value_id |
+-----------+----------+
| 2         | 7        |
+-----------+----------+
| 2         | 9        |
+-----------+----------+
| 3         | 8        |
+-----------+----------+

values
+---------------+----------------+-------+
| value_id (pk) | attribute_name | value |
+---------------+----------------+-------+
| 7             | age            | 35    |
+---------------+----------------+-------+
| 8             | age            | 28    |
+---------------+----------------+-------+
| 9             | gender         | male  |
+---------------+----------------+-------+


How do I join the three tables to display something like this?

+-----------+----------+-----------------+--------+
| person_id | value_id | attribute_name  | value  |
+-----------+----------+-----------------+--------+
| 2         | 7        | age             | 35     |
+-----------+----------+-----------------+--------+
| 2         | 9        | gender          | male   |
+-----------+----------+-----------------+--------+
| 2         | NULL     | name            | NULL   |
+-----------+----------+-----------------+--------+
| 2         | NULL     | email           | NULL   |
+-----------+----------+-----------------+--------+
| 3         | 8        | age             | 28     |
+-----------+----------+-----------------+--------+
| 3         | NULL     | gender          | NULL   |
+-----------+----------+-----------------+--------+
| 3         | NULL     | name            | NULL   |
+-----------+----------+-----------------+--------+
| 3         | NULL     | email           | NULL   |
+-----------+----------+-----------------+--------+

原文:https://stackoverflow.com/questions/14674949
更新时间:2024-01-31 21:01

最满意答案

谢谢,@martync! 将我的评论作为答案重新发布,因为它实际上已经回答了问题。

文档明确指出“您不能在HTML文档中使用JavaScript来触发打印” ,并提供了如何使用Java API的示例。 Chrome for Android(至少是Beta)支持window.print()


Thanks, @martync! Reposting my comment as an answer, as it has turned out to actually answer the question.

The documentation explicitly says "You cannot use JavaScript in a HTML document to trigger printing", and provides an example of how to use the Java API. Chrome for Android (at least Beta) supports window.print().

相关问答

更多
  • 最后我得到了错误的解决方案。 我在用着: btn.post(new Runnable() { @Override public void run() { btn.requestFocus(); btn.setVisibility(0); } } 之后,当我想要显示按钮时,我正在开始一个新线程 Finally I got the solution of the error. I'm using: btn.post(new Runnable() { ...
  • 首先,字符串中的' s '应替换为\' : body = body.replace("'", "\\'"); 然后应该删除所有换行符: body = body.replaceAll(System.getProperty("line.separator"), " "); 所有问题都解决了 first the 's in String should be replaced with \' : body = body.replace("'", "\\'"); then all newline char sh ...
  • 您声明了文本,但没有使用它。 webview.loadUrl("javascript:(function() { " + "var text = 'HELLO';"+ "document.body.innerHTML = document.body.innerHTML.replace(/"+letter+"/g, ''+text+'');"+ ...
  • 不要将UIWebView用于针对iOS 8及更高版本的新代码,而是使用WKWebView 。 Apple在UIWebView文档中有这样的说法: 在iOS 8及更高版本中运行的应用程序中,使用WKWebView类而不是使用UIWebView。 此外,如果渲染不应运行JavaScript的文件,请考虑将WKPreferences属性javaScriptEnabled设置为NO。 以下是使用WKWebView评估Javascript的WKWebView : self.webView.evaluateJavaSc ...
  • 请在触发loadUrl-method之前设置您的webview设置: WebView view =(WebView)findViewById(R.id.webview); WebSettings settings = view.getSettings(); settings.setJavaScriptEnabled(true); view.loadUrl("file:///android_asset/first.html"); Aargh! Stupid mistake i ...
  • 来自assets文件夹 webview.loadUrl("file:///android_asset/file.html"); 从特定文件夹 webview.loadUrl("file:///data/data/com.example.example/files/file.html"); from assets folder webview.loadUrl("file:///android_asset/file.html"); from specific folder webview.loadUrl ...
  • Android应用程序的结构包含许多组件:活动,片段,服务,适配器,模型和控制器/业务类。 每个组件都extends了一个特定的android类。 例如,活动扩展了Activity类或AppCompatActivity类。 片段可以扩展Fragment类,服务扩展Service类,等等... 有一些方法只能用于活动,因为它们是Activity类方法(或方兴未艾)。 因此,如果您需要使用getActivity()方法,该方法可以被Fragment使用,但是您不在片段中,则需要以其他方式获取活动。 例如: pr ...
  • 谢谢,@martync! 将我的评论作为答案重新发布,因为它实际上已经回答了问题。 该文档明确指出“您不能在HTML文档中使用JavaScript来触发打印” ,并提供了如何使用Java API的示例。 Chrome for Android(至少是Beta)支持window.print() 。 Thanks, @martync! Reposting my comment as an answer, as it has turned out to actually answer the question. T ...
  • 实际上有一种方法可以将View所有内容添加到Canvas 。 它是: view.draw(canvas); 来自Android Developer:查看 : public void draw (画布帆布) 在API级别1中添加手动将此视图(及其所有子级)渲染到给定的Canvas。 在调用此函数之前,视图必须已完成完整布局。 实现视图时,实现onDraw(android.graphics.Canvas)而不是重写此方法。 如果确实需要覆盖此方法,请调用超类版本。 参数 canvas要呈现视图的Canvas。 ...
  • 打印WebView将作为Java 8的功能添加。 您可以下载将实现该功能的Java 8预发行版 。 Java 8将于明年3月发布。 功能跟踪器: RT-17666 Webview和HTMLEditor应支持打印其内容 附注 :在您发布的代码中,您将JavaFX和Swing代码混合在同一个线程上。 通常,您不应该这样做=> 有关详细信息,请参阅JavaFX Swing互操作性教程 。 Printing WebView will be added as a feature for Java 8. You can ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)