RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-205620

Joshua's questions

Martin Hope
Joshua
Asked: 2022-03-04 20:21:13 +0000 UTC

如何使用链接表中的多个组进行 sql 查询?

  • 0

我们需要获取 table1 中每条记录的 cdr 和 dxf 格式的文件数。并找到有 2 个 cdr 文件和 4 个 dxf 文件的条目。

create table table1
(
   id int, 
   name varchar(255)
);
create table table2
(
   id int,
   table1_id int,
   filename varchar(255),
   filetype varchar(255)
);
insert into table1 (id,name) values
(123, 'name123'),
(124, 'name124'),
(125, 'name125'),
(126, 'name126'),
(127, 'name127'),
(128, 'name128')
insert into table2 (id,table1_id,filename,filetype) values
(1, 123, 'file1', 'cdr'),
(2, 123, 'file1', 'dxf'),
(3, 123, 'file2', 'cdr'),
(4, 123, 'file2', 'dxf'),
(5, 123, 'file3', 'dxf'),
(6, 123, 'file4', 'dxf'),
(7, 124, 'file11', 'cdr'),
(8, 124, 'file11', 'dxf'),
(9, 124, 'file12', 'cdr'),
(10, 124, 'file12', 'dxf')
select * from table1
编号 | 姓名   
--: | :------
123 | 名称123
124 | 名称124
125 | 名称125
126 | 名称126
127 | 名称127
128 | 名称128
select * from table2
编号 | table1_id | 文件名 | 文件类型
-: | --------: | :------- | :--------
 1 | 123 | 文件1 | cdr     
 2 | 123 | 文件1 | dxf     
 3 | 123 | 文件2 | cdr     
 4 | 123 | 文件2 | dxf     
 5 | 123 | 文件3 | dxf     
 6 | 123 | 文件4 | dxf     
 7 | 124 | 文件11 | cdr     
 8 | 124 | 文件11 | dxf     
 9 | 124 | 文件12 | cdr     
10 | 124 | 文件12 | dxf     
-- пример рабочего запроса. но в нем только по типу cdr ищется.

SELECT table1.id, count(table2.filetype) as cdrCount
FROM table1
INNER JOIN table2 ON table1.id = table2.table1_id
WHERE table2.filetype = 'cdr'
GROUP BY table2.table1_id, table2.filetype
HAVING COUNT(table2.filetype) = 2
编号 | cdrCount
--: | --------:
123 | 2
124 | 2
-- ЭТОТ ЗАПРОС НЕ РАБОТАЕТ

-- Ожидаемый результат:
-- ----------------------------
-- | id  | cdrCount | dxfCount |
-- |-----|----------|----------|
-- | 123 |    2     |    4     |  
-- -----------------------------

SELECT table1.id, count(t21.filetype) as cdrCount, count(t22.filetype) as dxfCount
FROM table1
INNER JOIN table2 t21 ON table1.id = t21.table1_id
INNER JOIN table2 t22 ON table1.id = t22.table1_id
WHERE t21.filetype = 'cdr' AND t22.filetype = 'dxf'
GROUP BY t21.table1_id, t21.filetype, t22.table1_id, t22.filetype
HAVING COUNT(t21.filetype) = 2 AND COUNT(t22.filetype) = 4
编号 | cdr计数 | dxfCount
-: | --------: | --------:

db<>在这里摆弄

mysql
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-09-12 17:05:02 +0000 UTC

如何编写具有多个连接的 sql 查询?

  • 0

您需要从表中选择记录productwhere product.avaibility_poition = 1for which: product.id= priority_category_product.product_id,prirority_category_product.category_id = 55并且priority_category_product.vehicle_group_id等于 group for which vehicle.model_id = 22,vehicle.brand_id = 33

有一个请求。

SELECT product.id FROM product
INNER JOIN priority_category_product
    ON product.id = priority_category_product.product_id
WHERE priority_category_product.category_id = 55
    AND priority_category_product.vehicle_id = ?????...

如何更进一步?

表结构:

create table product
(
  id int,
  category_id int,
  name text,
  avalibility_position int
)
// Таблица связей
create table priority_category_product
(
  id int,
  category_id int,
  vehicle_group_id int,
  product_id int,
  position int
);
create table vehicle_group
(
  id int,
  name text
)
// Таблица связей
create table vehicle_group_vehicle
(
  id int,
  vehicle_group_id int,
  vehicle_id int
)
create table vehicle
(
  id int,
  brand_id int,
  model_id int
)

在这里摆弄

mysql
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-07-22 16:25:53 +0000 UTC

如何编写sql查询根据特定字段的值更新表的不同字段

  • 3

是否可以通过一个请求来做到这一点?

如果date2 IS NOT NULL: UPDATE table SET date1 = date2, date2 = NULL, status = 1 WHERE id IN (123,124,125)
如果date2 = NULL: UPDATE table SET status = 1 WHERE id IN (123,124,125)

mysql
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-01-24 21:54:02 +0000 UTC

带条件的复杂sql查询

  • 0

帮助进行sql查询。有表:

tbl_article(id, title)
tbl_category(id, title)
tbl_tag(id, title, geotag)

和链接表:

tbl_category_articles(id, category_id, article_id)
tbl_article_tag(id, article_id, tag_id)

您需要选择所有记录,从tbl_category_articles哪里category_id = 177,如果article没有标签,哪个字段有geotag = 1。一般来说,我不知道如何geotag实施检查。

我的错误要求:

SELECT * FROM `tbl_category_articles` ca
INNER JOIN tbl_article_tagnew at
ON ca.article_id = at.article_id
INNER JOIN tbl_tagnew t
ON at.tag_id = t.id
WHERE ca.category_id = 177
AND t.geotag = 0
mysql
  • 2 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-09-07 17:06:09 +0000 UTC

自动点击一个元素

  • 1

加载文档时,单击具有clearsearchclass400 毫秒延迟的类的元素:

$(document).ready(function(){
 setTimeout('document.getElementsByClassName("clearsearchclass")[0].click()', 400);
});

如果您删除setTimeout,则不会发生点击。我怎样才能立即点击?

javascript
  • 2 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-31 21:24:39 +0000 UTC

删除请求无效

  • 2

有一个查询成功返回结果:

SELECT * FROM tbl_article_tags t1
       WHERE tag_id = '16256'
       AND EXISTS(SELECT 1 FROM tbl_article_tags t2
                  WHERE t1.article_id=t2.article_id
                  AND tag_id = '17000')

替换SELECT *为DELETE,现在抛出错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't1 WHERE tag_id = '16256' ' at line 1

有谁知道为什么会这样?

mysql
  • 2 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-31 15:04:20 +0000 UTC

歪曲地生成人类可读的 URL [关闭]

  • 1
关闭 这个问题是题外话。目前不接受回复。

问题是一个不再复现的issue,或者错别字引起的。虽然类似的问题可能与此站点相关,但此问题的解决方案不太可能对未来的访问者有所帮助。像这样的问题通常可以通过编写和研究一个最小的程序来避免,在发布问题之前重现问题。

6 年前关闭。

改进问题

他在规则urlManager中写道:

'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>/<id:\d+>/<name:\w+>' => '<controller>/<action>',

我生成网址:

$this->createUrl('article/tag', ['id' => $model->id, 'name' => $model->name]); //$model->id=1; $model->name='newname'

我期待这个 URL:http://domain.ru/article/tag/1/newname
但我得到这个:http://domain.ru/article/tag/1/?name=newname

似乎根本就没有涉及到第二条规则。
我试图删除第一条规则,并且 URL 形成了它应该形成的,但是在没有参数的 URL 的页面上name(例如http://domain.ru/article/tag/1),如果我想访问URL,$_GET['id']就会发生错误Undefined index: id。简而言之,链接只有在有 2 个参数时才有效

php
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-16 17:40:44 +0000 UTC

无法添加 WHERE 查询

  • 10

此查询返回包含 4 列的记录:id, alias, name, status。

 SELECT DISTINCT t.id, t.alias, t.name,
 CASE WHEN at.tag_id IS NULL THEN 0 ELSE 1 END AS status
 FROM tbl_tag t LEFT JOIN tbl_article_tags at
 ON t.id = at.tag_id

如何添加条件WHERE status = 1?如果你加上了,那么mysql会报错:

#1054 -“where 子句”中的未知列“status”

mysql
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-16 14:52:04 +0000 UTC

如何根据其中存在一个值来设置样本中第1列或第0列的值?

  • 4

我有一个获取请求:

SELECT t.id, t.alias, t.name, at.tag_id as status
FROM tbl_tag t LEFT JOIN tbl_article_tags at
     ON t.id = at.tag_id

我们需要它返回一个结果,其中状态列将填充 1(如果单元格有值)或 0(如果单元格为 NULL)。如何实施?

mysql
  • 2 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-15 15:15:01 +0000 UTC

如何查询删除的SQL,条件是另一个条件有一条记录?

  • 1

有一个 article_tags 表

id  art_id  tag_id
1     81     21
2     81     22
3     82     23
4     83     24

还有两个变量: $old_tag = 21-要删除
$new_tag = 22的标签,-要保留的标签

tag_id = $old_tag如果存在相同art_id但带有的条目,如何进行查询以删除 c 条目tag_id = $new_tag?在这种情况下,应该删除第一个条目。

php
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-14 17:32:48 +0000 UTC

如何通过单击打开的对话框找出对话框中输入的 ID?

  • 0

通过单击输入调用该对话框。如何确定在对话框中调用它的输入的 ID?也就是说,我们需要这样的功能: ,只是不需要手动document.getElementById("oldtag").value = val;指定输入。它有必要自行决定,因为使用相同对话框的id其他人会有更多的输入id

对话连接:

<div style='display:none;' id='select_tag'>
    <?php require_once __DIR__.'/../tag/_tag.php'; ?>
</div>

单击时打开对话框的表单:

<input id="oldtag" name="Tag[name]" onclick="$('#select_tag').dialog('open');" value="<?=$model_tag->name?>"  type="text" required/>
javascript
  • 2 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-08-11 18:19:59 +0000 UTC

如何在表单文本输入末尾发送ajax请求?

  • 1

有input与id = "tagname"。现在,在输入每个字母后,将执行一个 ajax 请求。

$("#tagname").bind('input',function(e){
        $.ajax({ // Тело ajax запроса });
});

如何使发送延迟 2 秒?试过这样的:

setTimeout(function() {
        $.ajax({ // Тело ajax запроса });
},2000);

添加了一个延迟,但在它之后,发出了几个 ajax 请求(取决于输入的字符数)。并且有必要在输入结束时执行一个请求。

也就是说,在每次按下按钮后,如果在这 2 秒内输入了另一个字符,则应重置计数器。

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Joshua
Asked: 2020-07-27 21:47:40 +0000 UTC

如何遍历多个数组并将它们合并为一个?

  • 1

我如何生成$i以便第一个foreach填写$artRows此表单:
array(1 => array(2, 'id1', 'title1'), 2 => array(2, 'id2', 'title2'), 3 => ...); 第二foreach个是同一类型,只有它的第一次迭代应该继续计算 $i,那些可以说是开始向末尾添加元素。

            $artRows = array();
            foreach ($rows2 as $row2) {
                $artRows[$i]['tbl'] = 2;
                $artRows[$i]['id'] = $row2['id'];
                $artRows[$i]['title'] = $row2['title'];
            }

            foreach ($rows as $row) {
                $artRows[$i]['tbl'] = 1;
                $artRows[$i]['id'] = $row['id'];
                $artRows[$i]['title'] = $row['title'];
            }
php
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5