mysql in id 计算count_mysql查询来计算id(mysql query to count id)

mysql查询来计算id(mysql query to count id)

使用mysql我试图计算所有表where tid='any tid'的ID, where tid='any tid'我试过跟随查询,它"Column 'tid' in where clause is ambiguous"给出"Column 'tid' in where clause is ambiguous" 。 我需要使用加入吗?

SELECT count('id') as reccount

FROM table1,table2,table3

WHERE tid= '101'

AND `status` = 1

我有表格结构,

table 1:

------------------------------

id tid status ........

1 101 1

2 102 1

table 2:

------------------------------

id tid status ........

1 101 1

2 102 1

table 3:

------------------------------

id tid status.......

1 101 1

2 102 1

table 4: It contains tid

--------------------------

tid tname .....

101 xyz

102 abc

Using mysql I am trying to count the ID from all tables where tid='any tid' I have tried following query, its giving "Column 'tid' in where clause is ambiguous". Do I need to use join ?

SELECT count('id') as reccount

FROM table1,table2,table3

WHERE tid= '101'

AND `status` = 1

I have table structure like,

table 1:

------------------------------

id tid status ........

1 101 1

2 102 1

table 2:

------------------------------

id tid status ........

1 101 1

2 102 1

table 3:

------------------------------

id tid status.......

1 101 1

2 102 1

table 4: It contains tid

--------------------------

tid tname .....

101 xyz

102 abc

原文:https://stackoverflow.com/questions/14973163

2020-06-17 15:06

满意答案

您没有提供所需的输出,但如果您的目的是从所有三个表中获得总行数(从原始查询中推导出),那么您可以执行以下操作:

SELECT COUNT(`id`) AS reccount

FROM

(SELECT `id` FROM table1

WHERE tid= '101' AND `status` = 1

UNION ALL

SELECT `id` FROM table2

WHERE tid= '101' AND `status` = 1

UNION ALL

SELECT `id` FROM table3

WHERE tid= '101' AND `status` = 1) t

You didn't provide desired output, but if your intent is to get just a total number of rows (deducing from your original query) from all three tables then you can do:

SELECT COUNT(`id`) AS reccount

FROM

(SELECT `id` FROM table1

WHERE tid= '101' AND `status` = 1

UNION ALL

SELECT `id` FROM table2

WHERE tid= '101' AND `status` = 1

UNION ALL

SELECT `id` FROM table3

WHERE tid= '101' AND `status` = 1) t

2013-02-20

相关问答

使用WHERE orderid IN(7,6,8,9,10,11,12,13,14) 所以查询将是: 'SELECT count(id) FROM bl_orderitems WHERE orderid IN(7,6,8,9,10,11,12,13,14)';

use WHERE orderid IN(7,6,8,9,10,11,12,13,14) so the query would be: 'SELECT count(id) FROM bl_orderitems WHERE orderid ...

子查询和主查询之间缺少链接以获取相关计数 (SELECT COUNT(order_id) FROM orders WHERE order_status = 'success'

and customer_id = c.customer_id --- you need to link the sub and the mainquery

)

Missing link between subquery and main query to get the related count (SELECT...

您可以做的是在列上使用COUNT DISTINCT ,该列与您要计算的值唯一不同,即: ...

COUNT(DISTINCT qa.id) total_quiz,

COUNT(DISTINCT ct.course_id) total_courses

...

SqlFiddle在这里 What you can do is use COUNT DISTINCT on a column which varies uniquely with the value that you are trying...

要将这些值输入T,您必须找出他们在T1中的身份并再次使用T1加入它们,以获得正确的行数: INSERT INTO T (id, p, o)

SELECT TT.*

FROM T1 TT

INNER JOIN (

SELECT id, p1, l

FROM T1

GROUP BY p1

HAVING COUNT(*) > 1

) a ON a.p1 = TT.p1;

sqlfiddle演示 这是如何工作的: SELECT id, p1, l

FROM T1

GROUP BY p...

这是COUNT与GROUP BY最基本的用法: SELECT UserId, COUNT(*)

FROM badges

GROUP BY UserId

ORDER BY COUNT(*) DESC

This is the most basic use of COUNT with GROUP BY: SELECT UserId, COUNT(*)

FROM badges

GROUP BY UserId

ORDER BY COUNT(*) DESC

您可以将其分配给用户变量: INSERT INTO actions ...;

SET @action_id = LAST_INSERT_ID();

然后,您可以在插入phrases所有INSERT查询中使用@action_id 。 INSERT INTO phrases (action_id, phrase) VALUES (@action_id, "Whatever");

INSERT INTO phrases (action_id, phrase) VALUES (@action_id, "...

您没有提供所需的输出,但如果您的目的是从所有三个表中获得总行数(从原始查询中推导出),那么您可以执行以下操作: SELECT COUNT(`id`) AS reccount

FROM

(SELECT `id` FROM table1

WHERE tid= '101' AND `status` = 1

UNION ALL

SELECT `id` FROM table2

WHERE tid= '101' AND `status` = 1

...

格式化的 SQL: SELECT `users`.`staff_id`, `user_info`.`name`, `user_info`.`surname`,

`teams`.`team_name`, `departments`.`dept_name`,

COUNT(quality.qms_id) AS num_assessments,

(SELECT (AVG(quality_results.total_result))) AS average_resul...

您遇到的问题是您尝试从双引号内访问数组元素。 您可以通过将其包装在大括号{$row['User_ID']}来完成此工作。 为了使代码更具可读性并避免此问题,只需连接或使用echo的值列表。 我还建议使用htmlspecialchars()来确保您创建有效的HTML。 echo '

',

'',

htmlspecialchars($row...

您可以使用GROUP BY和COUNT来实现此目的。 子查询不是必需的。 SELECT goal_results.user_id, COUNT(*) qty

FROM goals

LEFT JOIN goal_results ON goals.id = goal_results.goal_id

WHERE goals.enabled = 1 AND goal_results.validation = 'accepted'

GROUP BY goal_results.user_id

You can...

相关文章

mysql in根据查询时,返回结果是自行排序的​,如果要按照我们查询的ID进行排序,要用到order

...

查询一个对象(实体类必须有一个不带参数的构造方法),使用select查询,基于投影的查询,通过在列表中

...

Solr1.4 Both delete by id and delete by query can b

...

Solr1.4 Both delete by id and delete by query can b

...

最近在测试hive导入solr,github上有个相关的代码 https://github.com/c

...

初步接触solr是对其query的各个参数都不是很了解,现在做一个总结,以便日后查看使用 各个参数及意

...

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom

...

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom

...

用source c:\xxx.sql,出现Ignoring query to other databa

...

查询操作符(Query Operators)可以让我们写出复杂查询条件,让我们使用的过程更加灵活。官方

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值