- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个表,我想将 a 联接到 b 并 for eace join 获取未联接的结果
表格像素
+----+------------+------------+-------------------+--------+------+------------+
| id | account_id | project_id | uuid | name | type | date |
+----+------------+------------+-------------------+--------+------+------------+
| 10 | 2 | 3 | E03AA~F86A1~7C661 | test 1 | 0 | 1420553362 |
| 11 | 2 | 3 | A3E3B~B4182~DA556 | test 2 | 1 | 1420553933 |
| 9 | 1 | 1 | 57EAE~E633C~B929F | test 3 | 1 | 1420041387 |
+----+------------+------------+-------------------+--------+------+------------+
表pixel_tags
+----+------------+-------------------+--------------+--------------+------------+
| id | project_id | pixel | tag | name | date |
+----+------------+-------------------+--------------+--------------+------------+
| 6 | 0 | 57EAE~E633C~B929F | facebook-cpc | facebook-cpc | 1420041606 |
| 7 | 0 | 57EAE~E633C~B929F | google-cpc | google-cpc | 1420041621 |
| 8 | 0 | A3E3B~B4182~DA556 | utm_google | test | 1420554059 |
+----+------------+-------------------+--------------+--------------+------------+
这是我的查询
SELECT
`pixel`.*,
(CASE WHEN `pixel_tags`.`name` <>'' THEN `pixel_tags`.`name` ELSE `pixel`.`name` END ) `p_name`,
`pixel_tags`.`tag`
FROM `pixel`
LEFT JOIN `pixel_tags` ON `pixel`.`uuid`=`pixel_tags`.`pixel`
WHERE `pixel`.`account_id`='1'
结果是如果像素有标签,它们将显示在名称中,但我需要返回两者,例如,如果一个像素有 2 个标签,我想要 3 行,1 行带有名称,2 行带有标签谢谢。
转储
-- phpMyAdmin SQL Dump
-- version 4.0.10.7
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: May 14, 2015 at 01:19 PM
-- Server version: 5.5.42-cll
-- PHP Version: 5.4.23
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `mslm_db`
--
-- --------------------------------------------------------
--
-- Table structure for table `pixel`
--
CREATE TABLE IF NOT EXISTS `pixel` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`project_id` int(11) NOT NULL,
`uuid` text NOT NULL,
`name` text NOT NULL,
`type` int(11) NOT NULL,
`date` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=22 ;
--
-- Dumping data for table `pixel`
--
INSERT INTO `pixel` (`id`, `account_id`, `project_id`, `uuid`, `name`, `type`, `date`) VALUES
(10, 2, 3, '75D79~535F8~96FA1~F1B5E~C21E7~E03AA~F86A1~7C661', '×—×ž×•×¦×™× ×–×” ××—', 0, 1420553362),
(11, 2, 3, '195A6~83005~4C660~62EF3~8C79A~A3E3B~B4182~DA556', '×—×ž×•×¦×™× ×–×” ×חות', 1, 1420553933),
(9, 1, 1, 'D0950~15D68~354C8~5FBAE~DAF05~57EAE~E633C~B929F', 'טורקיז', 1, 1420041387),
(12, 4, 5, 'E92E8~DEDA0~11571~86FEA~13AF9~B2266~F8EFD~FB9D3', 'חביתה', 0, 1420554873),
(13, 4, 5, '38FFD~3A1F4~A3CDE~7A90E~AF099~CD11D~28752~67D77', 'חלומי', 1, 1420555402),
(14, 4, 5, '9525D~A8682~1932E~85D96~B5830~03BF8~9C77D~7EBE2', 'סביח', 1, 1420555681),
(15, 5, 6, '3784E~151DA~7BFDE~C12F6~A6C01~435E3~36E4E~ED4AB', '×‘×™×§×™× ×™ בוטו×', 1, 1420556203),
(16, 1, 1, '1211B~9C86C~83024~9039C~43F8F~B639D~547EB~8CFAC', 'שולחן', 0, 1421322108),
(17, 1, 1, 'A8DF0~23617~904F6~94880~99192~4781E~D8712~221A7', 'כס×', 1, 1421322943),
(18, 1, 1, '0A492~EA76B~01948~061AB~A74A7~34F58~42DAC~366DE', 'חזותה', 0, 1421945914),
(19, 1, 20, '2E3FE~200C7~FC8E1~17323~A9A1D~6F278~CBECF~CDD6E', '×’× - מעיל', 0, 1422351583),
(20, 1, 20, '85CF8~71D5A~71C24~D9FC1~3A041~A1AC7~AB6CE~E1B1D', 'שפן של מורדי', 0, 1431527532),
(21, 1, 0, 'AF627~4E88E~13138~49BE4~49BB7~DAB92~DF35E~14C97', '', 0, 1431589094);
-- --------------------------------------------------------
--
-- Table structure for table `pixel_tags`
--
CREATE TABLE IF NOT EXISTS `pixel_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project_id` int(11) NOT NULL,
`pixel` text NOT NULL,
`tag` text NOT NULL,
`name` text NOT NULL,
`date` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
--
-- Dumping data for table `pixel_tags`
--
INSERT INTO `pixel_tags` (`id`, `project_id`, `pixel`, `tag`, `name`, `date`) VALUES
(6, 0, 'D0950~15D68~354C8~5FBAE~DAF05~57EAE~E633C~B929F', 'facebook-cpc', 'facebook-cpc', 1420041606),
(7, 0, 'D0950~15D68~354C8~5FBAE~DAF05~57EAE~E633C~B929F', 'google-cpc', 'google-cpc', 1420041621),
(8, 0, '195A6~83005~4C660~62EF3~8C79A~A3E3B~B4182~DA556', 'utm_google', 'גוגל גוגל', 1420554059),
(9, 0, '9525D~A8682~1932E~85D96~B5830~03BF8~9C77D~7EBE2', 'utm-facebook', 'פייסבוק', 1420556056),
(10, 0, 'A8DF0~23617~904F6~94880~99192~4781E~D8712~221A7', 'h_test', '×—× ×” בדיקה', 1421323080);
最佳答案
查询可能是 -
SELECT `pixel`.*,
`pixel_tags`.`name`as p_name,
`pixel_tags`.`tag`
FROM `pixel`
JOIN `pixel_tags` ON `pixel`.`uuid`=`pixel_tags`.`pixel`
WHERE `pixel`.`account_id`='1'
UNION
SELECT `pixel`.*, NULL , NULL
FROM `pixel`
WHERE `pixel`.`account_id`='1' AND `uuid` not in (select distinct pixel from pixel_tags);
我正在树立榜样-
mysql> select * from pixel;
+----+------------+------------+------+--------+------+------------+
| id | account_id | project_id | uuid | name | type | date |
+----+------------+------------+------+--------+------+------------+
| 10 | 2 | 3 | a | test 1 | 0 | 1420553362 |
| 11 | 2 | 3 | b | test 2 | 1 | 1420553933 |
| 9 | 1 | 1 | c | test 3 | 1 | 1420041387 |
+----+------------+------------+------+--------+------+------------+
3 rows in set (0.00 sec)
mysql> select * from pixel_tags;
+----+------------+-------+-----------+----------+------------+
| id | project_id | pixel | tag | name | date |
+----+------------+-------+-----------+----------+------------+
| 6 | 0 | c | facebook | facebook | 1420553606 |
| 7 | 0 | c | google | google | 1420041621 |
| 8 | 0 | b | do_google | test | 1420554059 |
+----+------------+-------+-----------+----------+------------+
3 rows in set (0.00 sec)
mysql> SELECT `pixel`.*,
-> `pixel_tags`.`name`as p_name,
-> `pixel_tags`.`tag`
-> FROM `pixel`
-> JOIN `pixel_tags` ON `pixel`.`uuid`=`pixel_tags`.`pixel`
-> WHERE `pixel`.`account_id`='2'
-> UNION
-> SELECT `pixel`.*, NULL , NULL
-> FROM `pixel`
-> WHERE `pixel`.`account_id`='2' AND `uuid` not in (select distinct pixel from pixel_tags);
+----+------------+------------+------+--------+------+------------+--------+-----------+
| id | account_id | project_id | uuid | name | type | date | p_name | tag |
+----+------------+------------+------+--------+------+------------+--------+-----------+
| 11 | 2 | 3 | b | test 2 | 1 | 1420553933 | test | do_google |
| 10 | 2 | 3 | a | test 1 | 0 | 1420553362 | NULL | NULL |
+----+------------+------------+------+--------+------+------------+--------+-----------+
2 rows in set (0.00 sec)
如果您仍然没有得到那么它可能会有所帮助。我已从两个查询中删除了 where 中的 account_id 条件。
mysql> SELECT `pixel`.*,
-> `pixel_tags`.`name`as p_name,
-> `pixel_tags`.`tag`
-> FROM `pixel`
-> JOIN `pixel_tags` ON `pixel`.`uuid`=`pixel_tags`.`pixel`
-> UNION
-> SELECT `pixel`.*, NULL , NULL
-> FROM `pixel`
-> WHERE `uuid` not in (select distinct pixel from pixel_tags);
+----+------------+------------+------+--------+------+------------+----------+-----------+
| id | account_id | project_id | uuid | name | type | date | p_name | tag |
+----+------------+------------+------+--------+------+------------+----------+-----------+
| 9 | 1 | 1 | c | test 3 | 1 | 1420041387 | facebook | facebook |
| 9 | 1 | 1 | c | test 3 | 1 | 1420041387 | google | google |
| 11 | 2 | 3 | b | test 2 | 1 | 1420553933 | test | do_google |
| 10 | 2 | 3 | a | test 1 | 0 | 1420553362 | NULL | NULL |
+----+------------+------------+------+--------+------+------------+----------+-----------+
4 rows in set (0.02 sec)
关于php - mysql 左连接和返回已连接和未连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30233205/
这个问题已经有答案了: Declaring multiple object pointers on one line causes compiler error (5 个回答) 已关闭 6 年前。 l
我目前正在学习语言处理器,经常出现的一个话题是语法中元素的使用方向。从左到右或从右到左。 我理解这个概念,但似乎有很多方法可以编写这些规则,我不确定它们是否都相同。到目前为止我看到的是: 右/左递归,
我有一个很长的线性(分支不多)流程图,在 graphviz 中显示为要么太高而无法放在单个页面上,要么太宽(如果方向是从左到右) 是否有一种简单的方法可以让 graphviz 以从左到右,然后向下,然
我一直摸不着头脑,但运气不好。设计器有一个包含 3 栏的站点、两个侧边栏和一个主要内容区域。 专为桌面设计,左栏、主要内容、右栏。但是,在较小的设备上,我们希望首先堆叠主要内容。 所以通常情况下,你可
我想要从上到下和从左到右组织的 css block 。 为了更好地解释这是一张图片,其中包含我到目前为止所获得的内容以及我希望使用 CSS 实现的内容: 代码如下: HTML: 1 2 3 4 5
当我问this question时,答案之一(现已删除)建议Either类型对应Curry-Howard correspondence中的XOR而不是OR,因为它不能同时是Left和Right。 真相
我有一个程序,如果用户按住向左或向右箭头键, Angular 色会逐渐朝那个方向加速,并最终达到最大速度。松开按键后, Angular 色逐渐减速,直至完全停止。 我的右方向键没问题,但左方向键坏了。
今天很简单的一个。我有一个专栏,我们称之为标题,有一堆项目标题。我需要从“:”的左侧拉出所有内容并进行左/右修剪(稍后我将在连接中使用它,但我现在只需要一个包含新数据的列) .下面是当前列的示例: 这
我正在尝试将图表中的列与左侧对齐。默认情况下,它们位于中间。 我在 API 文档中找不到任何关于此的信息。 Here是一个 jsFiddle 测试。 最佳答案 在 highcharts api 中,您
左旋转进位和右旋转进位指令有哪些实际用途? 在我的汇编课上,我们无法想出一个有用的好例子。 最佳答案 如果您想将位从一个操作数移出并移入另一个操作数: SHL EAX, 1 ; mov
我有一个查询,它使用 eqjoin 从两个不同的表返回以下数据。我想将 left 和 right 结合起来,而不是执行 zip() (重写 name > 和 joined_at),我想将右侧对象的属性
我使用 firebase API。发送和检索消息。但是,我在尝试为发送者/检索者设置布局时遇到麻烦,以便消息将左/右对齐。目前我只有发送者/检索者都使用的一种布局,但不确定如何设置不同的布局。 pub
我的菜单基本上是一个水平项目滑动条。所有菜单项都有特定的默认 CSS 属性。我希望这些项目在到达主容器的中心时更改其大小和左/右边距,并在离开主容器(或位于主容器之外)时重置为默认值。请参阅我的原理图
我有一个引用表,在这个表中有 3 个字段(Id、User1、User2)。 User2 字段可以为空,但我们在不使用时使用 0。 当我执行下面的 Linq 查询时,User2 == 0 的记录不是结果
不知道如何解决这个问题。 我有两个表结果和受访者 我需要查明受访者表中是否有任何行具有completion =“Complete”,但它们的respondent_id(在结果表和受访者表中)不在结果表
我正在尝试访问三个表以获得类似这样的内容: +------+------+------+ | ITEM | PCS | CSS | +------+------+------+ | 1099 |
left 和 right join 有区别吗,下面的sql 语句结果一样,但是两者的性能是一样的吗? SELECT count(*) FROM writers RIGHT JOIN blogs O
当我使用 LEFT() 使用以下代码从数据库中获取值时 $select="SELECT LEFT(description,500) FROM tbl_news where id='$id'"; $qu
当我将鼠标悬停在水平导航菜单上的页面名称上时,相关子页面会 float 在下方。 目前这些显示居中,我如何对齐它们以便它们向左对齐(与导航菜单标题名称一致)。 你可以去看到这个 http://79.1
在下面的引导网格示例中,它使用 col-sm 和 col-sm-push/pull。col-sm-push 指定了左/右值(偏移量)。 我不太清楚它是如何工作的。 第二个 float 元素来到第一个
我是一名优秀的程序员,十分优秀!