小编mad*_*pie的帖子

SQL-向结果集中添加额外的行

我要完成一些SQL任务,但老实说,我不知道该如何处理。

请考虑下表:

**Product ID | Product Name | Product Cat | Price | Amount Sold**
1            | product 1    | cat1        | 0.10  | 1000
2            | product 2    | cat1        | 0.50  | 10
....         | .....        | ......      | ...   | ....
500          | .....        | .......     | ...   | ....
501          | ......       | .......     | ....  | .....
....         | .......      | ......      | ..... | .....
Run Code Online (Sandbox Code Playgroud)

为了制作销售报告,我有一个SQL查询,该查询选择所有产品,对所有已售金额字段求和,并计算产品的总销售量。现在要求我执行以下操作:

对于某些特定产品ID(Fe 500、501),我将在结果集中“添加一行”,内容为:

**Product ID | Product Name | …
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server

3
推荐指数
1
解决办法
2078
查看次数

如果字符串以数字开头,则包含throws的xpath错误

我遇到了nokogiri和xpath的奇怪问题.我想解析一个HTML文档,并通过href值和它们包含的锚文本获取所有链接.

到目前为止这是我的xpath:

    xpath = "//a[contains(text(), #{link['anchor_text']}) and @href='#{link['target_url']}']"
    a = doc.search(xpath)
Run Code Online (Sandbox Code Playgroud)

只要link ['anchor_text']是没有数字的字符串,这就可以正常工作.

如果我试图获取锚文本"11example"的链接,则会抛出以下错误:

    Invalid expression: //a[contains(text(), 11example) and @href='http://www.example.com/']
Run Code Online (Sandbox Code Playgroud)

也许这只是一个愚蠢的错误,但我不明白为什么会出现这种错误.如果我在xpath中围绕#{link ['anchor_text']}添加一些引号,那么什么都不起作用.

编辑:这是示例HTML:

<!DOCTYPE html>
<head>
  <title>Example.com</title>
</head>
<body>
<p>
<strong>Here is some text</strong><br />
<a href="example.com" target="_blank">11example</a>Some text here and there
</p>
<p>
<strong>Another text</strong><br />
<a href="example.com/test" target="_blank">example.com</a>Some text here and there
</p>
</body>
Run Code Online (Sandbox Code Playgroud)

Edit2:如果我在irb控制台中手动运行这些查询,一切都按预期工作,但前提是我将文本放在引号中.

提前致谢!

亲切的问候,madhippie

ruby xpath ruby-on-rails nokogiri

1
推荐指数
1
解决办法
475
查看次数

标签 统计

nokogiri ×1

ruby ×1

ruby-on-rails ×1

sql ×1

sql-server ×1

t-sql ×1

xpath ×1