我想加入3个具有以下格式的列表:
List1:
CountryID | CountryData | regionUID
===================================
12 | Has good gras | 4567
12 | nice weather | 6789
16 | stormy weather | 1234
List2:
CountryID | CountryName
=======================
12 | green hill
16 | stormy mountain
List3:
regionUID | regionName
=======================
4567 | above 1000feet
6789 | on the ground
1234 | on the hill
Run Code Online (Sandbox Code Playgroud)
输出应如下所示:
CountryName | CountryData | regionName
==============================================
green hill | Has good gras | above 1000feet
green hill | nice weather …
Run Code Online (Sandbox Code Playgroud) 我使用左外连接在SQL中加入了两个表(见下文).
是否可以用其他数据填充空单元格?
(来自小提琴)
CREATE TABLE Data1
(cost_type nvarchar(10), contract nvarchar(10))
;
INSERT INTO Data1
(cost_type, contract)
VALUES
('LABR', 'contract1'),
('EQP', ''),
('RST', 'contract1')
;
CREATE TABLE data2
(cost_type nvarchar(10), contract nvarchar(10), Name nvarchar(max))
;
INSERT INTO data2
(cost_type,contract,Name)
VALUES
('LABR','contract1','John'),
('MAT','contract1','John'),
('EQP','','')
;
Run Code Online (Sandbox Code Playgroud)
当前正在运行的查询:
select * from data1 dt1
left outer join data2 dt2 on dt1.cost_type=dt2.cost_type
Run Code Online (Sandbox Code Playgroud)
我需要的结果如下:
COST_TYPE CONTRACT NAME
LABR, contract1, John
EQP, contract1, John
RST, contract1, John
Run Code Online (Sandbox Code Playgroud)
此结果基于查找CONTRACT列的最常用值并使用该值替换所有空值.我需要为NAME列做同样的事情.
我四处搜寻,一无所获.
我有2个表,并且不必查询数据库中的每个帖子,显示我需要以某种方式加入它们.
我想url
从pics
post表中获得具有该字段id的pics 表.现在pics
继承我的问题:该字段是一个以分隔的"列表"(4,1或32,4,32,2),因为每个帖子通常都有多个图片.
表设置:
帖子:
id | header | text | pics
| 1 xxx xxx 3,1
| 2 xxx xxx 2,10,4
| 3 xxx xxx 16,17,18,19
| 4 xxx xxx 11,12,13
Run Code Online (Sandbox Code Playgroud)
图片:
id | name | url
| 1 xxx xxx
| 2 xxx xxx
| 3 xxx xxx
| 4 xxx xxx
| 10 xxx xxx
| 11 xxx xxx
| 12 xxx xxx
| 13 xxx xxx
| 16 xxx …
Run Code Online (Sandbox Code Playgroud) 我正在尝试与MySQL进行多个内部联接,但我不断收到以下错误
#1064 - 您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在'on codes.code = votes.code ORDER BY date desc LIMIT 0,30'第2行附近使用正确的语法
SELECT * FROM codes
INNER JOIN user ON codes.userid = user.gid
INNER JOIN on codes.code = votes.code
ORDER BY date desc
Run Code Online (Sandbox Code Playgroud)
我这样做了吗?
我希望得到最近提交的十个补丁(前10个patchID desc)从下面的查询开始,我收到了一个错误10
.错误是syntax error, unexpected NUM, expecting END_OF_INPUT, or ';'
.可能会在以下查询中导致此错误?
SELECT TOP 10 synth.*
FROM (
SELECT p.`id`,
p.`patchName`,
p.`description`,
p.`tfsID`,
p.`codeRelease`,
s.`name`,
d.`deployStatus`,
d.`deployedDate`,
t.`testedStatus`,
t.`testedDate`
FROM `patches` AS p
JOIN `deployed` AS d ON p.`id` = d.`PatchID`
JOIN `servers` AS s ON d.`serverID` = s.`id`
JOIN `tested` AS t ON p.`id` = t.`patchID`
) synth
ORDER BY synth.id DESC
Run Code Online (Sandbox Code Playgroud) 我在MySQL中创建了一个相对简单的查询,JOIN
根据名字和姓氏匹配的位置给出了三个表.从那里开始,我想编写另一个查询,然后只显示那些没有得到匹配的记录JOIN
- 但我无法弄清楚如何做到这一点.我假设它与使用涉及类似NOT IN
和我的原始查询的子查询有关,但我无法得到它给我想要的结果.
这是我尝试提出的部分功能正常的解决方法:
SELECT *,
if(t2.first=t1.first AND t2.last=t1.last, "Match", "No Match") AS "t2 Match",
if(t3.first=t1.first AND t3.last=t1.last, "Match", "No Match") AS "t3 Match"
FROM t1
LEFT JOIN t2 ON t2.first=t1.first AND t2.last=t1.last
LEFT JOIN t3 ON t3.first=t1.first AND t3.last=t1.last
WHERE if(t2.first=t1.first AND t2.last=t1.last, "Match", "No Match")="No Match"
OR if(t3.first=t1.first AND t3.last=t1.last, "Match", "No Match")="No Match";
Run Code Online (Sandbox Code Playgroud)
我觉得这是相当简单和直接的事情,但我没有得到正确的结果.有人可以帮忙吗?
谢谢!
我正在尝试更好地理解SQL数据库中的JOIN或INNER JOIN多个表.
这是我有的:
SQL查询:
SELECT *
FROM csCIDPull
INNER JOIN CustomerData ON CustomerData.CustomerID = csCIDPull.CustomerID
INNER JOIN EMSData ON EMSData.EmsID = csCIDPull.EmsID
;
Run Code Online (Sandbox Code Playgroud)
这将返回NO结果,如果我删除该INNER JOIN EMSData
部分,它将提供来自CustomerData
和csCIDPull
表的信息.我的思维方式可能不正确.我已经说过5个表都带有一个int ID,这些ID也提交到一个表来组合所有表(MAIN表只包含ID,而其他表包含数据).
想我会拍你的人发帖看看我可能做错了什么.-谢谢
我有两个表'分钟'列.这些表与INNER JOIN连接在一起.现在我想打印两个表中的所有记录,分别列在'minute'列上
例
表1:名称 - 分钟
John - 1
Marc - 3
Run Code Online (Sandbox Code Playgroud)
表2:名称 - 分钟
Gareth - 2
Joe - 3
Run Code Online (Sandbox Code Playgroud)
输出:
John, Gareth, Marc, Joe
Run Code Online (Sandbox Code Playgroud)
这两个表必须保留两个单独的表.
我有两个JPA2注释类和一个工作JUnit测试,但他们决定添加唯一的约束,这会导致createManagerFactory失败.
以下是课程:
@Entity
@NamedQuery(
name="XmlConversion.Queries.XmlByPdfAndPdf2Xml",
query="SELECT c FROM XmlConversion c WHERE c.pdf = :pdfname AND c.pdf2xml_sha1 = :pdf2xml")
@Table(name = "xml_conversion", uniqueConstraints={
@UniqueConstraint(columnNames={"pdf_id", "pdf2xml_sha1"})})
public class XmlConversion implements java.io.Serializable {
private Integer id;
private Pdf pdf;
private Long xmlOutputSize;
private String pdf2xml_sha1;
private Integer durationMillisec;
private Date createdAt;
public XmlConversion() {
}
public XmlConversion(Pdf pdf, String pdf2xml_sha1_sourceforge) {
this.pdf = pdf;
this.pdf2xml_sha1 = pdf2xml_sha1_sourceforge;
}
public XmlConversion(Pdf pdf, Long xmlOutputSize, String gitVersion,
Integer durationMillisec) {
this.pdf = pdf;
this.xmlOutputSize = …
Run Code Online (Sandbox Code Playgroud) 我不知道我错过了什么,但我一直在与Twig战斗,无法找出我误解的地方.
我有三个实体:Product,ProductImage和Category
每个产品作为一个类别和一个类别有许多产品.每个产品都有很多图片.
我能够列出图像集,这不是问题.
问题是我无法获取Twig模板文件中每个产品的类别描述(product.categories.description),原样如下:
{% extends '::base.html.twig' %}
{% block body %}
<div id="vitrines">
{{ debug products }}
{% for product in products %}
<div class="boxVitrine">
{% for image in product.images %}
{% if(image.oneOfType == 'thumb') %}
<img src="{{ asset('bundles/artevitrinesite/products/') }}{{ image.filename }}" />
{% endif %}
{% endfor %}
<div class="info">
<div class="container">
<div class="top">
<div class="code">
Cod: <span class="red1"><strong>{{ product.code }}</strong></span>
<br />{{ product.categories.description }}
</div>
<div class="price">{{ product.price | bigprice | raw }}</div>
</div> …
Run Code Online (Sandbox Code Playgroud)