Tag Info

Hot answers tagged

2

According to comment you are not interested in users at all, you just want the person to be client or provider (boolean logic, so it can be both): WHERE (client.id IS NOT NULL OR provider.id IS NOT NULL)


1

Here's your query: SELECT T.location_id, GROUP_CONCAT(T.service_id) AS serviceids FROM `Table` AS T GROUP BY T.location_id HAVING serviceids IN ('2,3'); You could use ORDER BY inside the GROUP_CONCAT(): SELECT T.location_id, GROUP_CONCAT(T.service_id ORDER BY service_id ASC) AS serviceids FROM `Table` AS T GROUP BY T.location_id HAVING ...


1

Here, this might help SELECT stock_key "FUND_KEY", SUM(units) "UNITS", SUM(units * price) / SUM(units) "PRICE" FROM stock_mngmt_app WHERE USER_KEY = 'user_1' GROUP BY STOCK_KEY


1

Here's your query: SELECT concat("fund_key: ",stock_key,", units: ",sum(units),", price: ",round(sum(units*price)/sum(units),2)) as result FROM PRUEBA.new_table2 GROUP BY stock_key,user_key; Result:


1

SELECT ... FROM users u LEFT JOIN userroles ur ON ur.user_id = u.user_id AND ur.role_id = 2 WHERE ur.role_id IS NULL ORDER BY u.user_id ASC; Examine all rows of user, and their matching row from userroles with a role_is = 2 if it exists, eliminating the rows where it does indeed exist by requiring the role_id in the (non-existent) row to be null... ...


1

What you need is some Dynamic SQL. STEP 01 : Retrieve the DB SET @IMEI = 123456789123456; SELECT db INTO @db FROM imeiDB WHERE IMEI = @IMEI; STEP 02 : Create the SQL to do the INSERT into the retrieve DB SET @sql = CONCAT('INSERT INTO ',@db,'.table1 (IMEI,data) VALUES (',@IMEI,',"somestuff"'); SELECT @sql\G STEP 03 : Execute the SQL Statement you just ...



Only top voted, non community-wiki answers of a minimum length are eligible