Mysql 一个表中不同列的不同行数
我有一个填充的表簿(责任制),其中包括四列感兴趣的内容:Mysql 一个表中不同列的不同行数,mysql,sql,group-by,Mysql,Sql,Group By,我有一个填充的表簿(责任制),其中包括四列感兴趣的内容: text, amount, debit (account_number) , credit (account_number) 我想要一个列表,列出每列(借方、贷方、金额)中每个不同值的发生次数。我使用文本列过滤行,并将出现次数设置为大于1(具有oc>1):(例如带有“debit”)。这是我的疑问: SELECT 'debit' , fi , COUNT(fi) oc FROM ( SELECT debit fi, tex
text, amount, debit (account_number) , credit (account_number)
我想要一个列表,列出每列(借方、贷方、金额)中每个不同值的发生次数。我使用文本列过滤行,并将出现次数设置为大于1(具有oc>1):(例如带有“debit”)。这是我的疑问:
SELECT 'debit' , fi , COUNT(fi) oc FROM
(
SELECT debit fi, text
FROM book
WHERE text
LIKE '%Supermarket SMILE%'
) t1
GROUP BY fi
HAVING oc > 1
下面是该输出的一个示例(以及在查询中将借方替换为贷方或金额时的其他两列):
是否可以使用MySQL中的查询将所有这些合并到一个输出中?(我不再需要这些事件了):
创建一个临时表,并从3个表中选择一个表
INSERT INTO #tempTable
SELECT debit,t2.column1,t3.column1 etc ... and join on the other 2 tables and select
from those tables the columns you need as well.
谢谢。我想到了一个更直接的方法:没有插入、表格等,但我会试试。我已经试过了。很有效,谢谢。不过,我最终选择使用UNION将三个表放在一起,然后在php脚本中处理查询结果。
+-------+--------+--------+
| debit | credit | amount |
+-------+--------+--------+
| 70 | 89 | 136.95 |
| 111 | | 200.34 |
| | | 136.95 |
+-------+--------+--------+
INSERT INTO #tempTable
SELECT debit,t2.column1,t3.column1 etc ... and join on the other 2 tables and select
from those tables the columns you need as well.