Skip to content

Write a query to find logged user

I have a table “record” with the columns: How do I write query that will list the userId and month for any occasions where a user logged in more than 10 times in a month? Answer Assuming your record table as an entry per login. The query is relatively straight forward (here using PostgresSQL speci…

can we simplify “while” inside of “while”?

i need some little help ,,, I have a data like this.., (I use php mysql) Initially there was no problem with this, but as time goes by, my data is getting bigger and bigger. finally its made my program slow .. I think maybe because I used “while” inside of “while”. make SQL is called m…

MySQL: Updating multiple columns using if else

I need help to set a mySQL update query for my little project like below: In my table, there is a column REFERENCE which contains varchar like where the character before the symbol ‘_’ determines certain values for other columns like stated above. I am still fairly new to mySQL, so appreciates any…

Replace values for each ID and each month in IBM DB2 SQL?

I have about several milion record table in IBM DB2 with 4 columns: yeas, month, personal_number (2 milion), personal_id. The key is that I want to get same table from this one, but I want to fill in personal_id column value from last month (in all previous months). Point is to get 1-1: 1 personal_id relate t…

Using the Like operator with two fields

How do I use the Like operator to join two unidentical tables as below? My main problem is on how to compare the PO filed on tbl2 to the EditNo on tbl1 field. Please see sample tables and expected results below: tbl1: tbl2: Expected: Query: SELECT * FROM tbl2 INNER JOIN tbl1 ON tbl2.PONo LIKE EditNo.PO; Answe…

Order by a subtraction expression sql

I would like to perform an ORDER BY in sql that sorts the returned rows by their distance from my integer of interest. The expression would be ORDER BY (constant – ColumnName) ASC specifically, something like ORDER BY (10 – Distance) ASC. When I tried running this expression the distances were jus…