I have one Select SUM command that works:
# SIM Orders Pending by Customers for 3101708 IMSI SIMs with 5YY MSISDNs
SELECT accountname AS 'Account Name',
IF ((SELECT * FROM 5YYAccounts WHERE 5YYAccounts.accountid = T3101708.accountid) IS NULL , 'N','Y') AS '5YY MSISDN',
LPAD(CONCAT(FORMAT(SUM(quantity), 0)),15,' ') AS 'Quantity'
FROM T3101708
WHERE outputfilereceived IS NULL AND (SELECT * FROM 5YYAccounts WHERE 5YYAccounts.accountid = T3101708.accountid) IS NOT NULL
GROUP BY accountname, accountid
ORDER BY SUM(quantity) DESC;
After running this, I get following result:
+---------------------------------+------------+-----------------+
| Account Name | 5YY MSISDN | Quantity |
+---------------------------------+------------+-----------------+
| FCA - SXM - AT&T | Y | 48,000 |
| Numerex - AT&T | Y | 34,000 |
| Mytrex Inc. - AT&T | Y | 24,000 |
| Honda US - AT&T | Y | 18,000 |
+---------------------------------+------------+-----------------+
3 rows in set (0.03 sec)
Based on the result above, I want to SUM the last column by having following Select SUM command:
SELECT SUM(
SELECT SUM(quantity)
FROM T3101708
WHERE outputfilereceived IS NULL AND (SELECT * FROM 5YYAccounts WHERE 5YYAccounts.accountid = T3101708.accountid) IS NOT NULL
GROUP BY accountname, accountid
);
For this time, I am getting an error in mySQL:
ERROR 1064 (42000): 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 'SELECT SUM(quantity) FROM T3101708 WHERE outputfilereceived IS NULL AND' at line 2
What did I code wrong here?
Thank you. Bobby
1 Answer 1
SELECT
DISTINCT a.label
,(SELECT SUM(stat_column)/total_stat_col_records FROM table_a AS b WHERE b.label=a.label) AS frequency
FROM table_a AS a
ORDER BE frequency DESC;
Where you want the unique distinct label
and the sum of the stat_column
and the total is the number of stat_column
records. This gets the percent based on number of records.
SELECT
. I think you try to use multi-query with the method which does not allow this.