Tag Info

New answers tagged

0

ok, I solved this by: select * from ( select id,id_operator,denumire,loc_den,str, row_number() over (partition by id_operator,loc_den,str order by id_operator) as no from rap where is_punct_lucru=1 order by id_operator ) where no>1


2

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

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

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... ...


0

If joining is "optional", then it is not an inner join, by definition. Consider investigating left joins.


0

I don't know if you still need this query or even if I understood your question correctly. But if you need a query that shows the 'Translator of the month' (Top Translator per month). SELECT CONCAT(yr,'/', mnt) AS `Year/Month`,user_id,totalTrans FROM ( SELECT YEAR(date_added) as yr ,MONTH(date_added)as mnt, user_id, COUNT(1) ...


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 ...


0

My guess is query2 (not exactly the same as query 1 though), but you will have to check the plan to be sure. Btw: FETCH FIRST 1 ROWS ONLY is the standard equivalent to LIMIT, it is supported by DB2 LUW (>= 7), Oracle (>= 12c), PostgreSQL (>= 8.4) and SQL server (>= 2012). Yet another option is to use an analytical function like rank: SELECT age, name ...


0

I'm not sure if this is as platform independent as you think but I've been doing some fairly extensive testing on this in SQL Server recently and the first query was interestingly the fastest. This was comparing against a number of "tricks" in SQL Server including using CROSS APPLY and windowing functions. But again YMMV in PostgreSQL. Unless I'm mistaken ...



Top 50 recent answers are included