当前位置: 动力学知识库 > 问答 > 编程问答 >

sum - How to hide columns? MySQL

问题描述:

I have a code I've made but I'd like to hide the column. So that it only shows the storeID instead of the SALARY along with it. I know I need to wrap it around in another set of brackets, but don't know where to do that. Also can anyone tell me a technique to identify where to use the brackets? Sorry, not too familiar with MySQL, but have been learning for couple of weeks now. Just finished the diagrams with Chen Notations, now the codes.

SELECT storeID, SUM(SALARY) FROM STORE

JOIN EMPLOYEE

WHERE SALARY < expenditure;

Currently it's displaying:

| storeID | | SUM(SALARY) |

| 1 | | £30000 |

| 2 | | £25000 |

| 3 | | NOTHING |

I want the second column SUM(SALARY) to be hidden. Thanks in advance.

EDIT: I wasn't being too clear. I needed to calculate the SALARY (sum of all salaries from each store), and find the storeID's with SALARY < expenditure.

EMPLOYEE = SALARY

STORE = storeID and expenditure.

网友答案:
SELECT StoreId
FROM
(
   SELECT storeID, SUM(SALARY) FROM STORE
   JOIN EMPLOYEE
   WHERE SALARY < expenditure
)

this should work ;)

网友答案:

try this

    SELECT storeID  FROM STORE
    JOIN EMPLOYEE
    WHERE SALARY < expenditure;
网友答案:

Yes you will need an Alias for this

SELECT x.name, x.branch
FROM (

SELECT person.name AS name, person.email, branch.name AS branch
FROM person
JOIN branch ON person.branch_id = branch.id
)x

So I name my query block with x, even you can reference by x like

x.name
x.branch
分享给朋友:
您可能感兴趣的文章:
随机阅读: