I need to ‘name’ categories: mycat is a text column with possible values ‘0’ to ‘4’. That works OK, but I have some an error in my program which very rarely writes null (or ” as I can see in pgAdmin). In such cases I have to treat that ” the same as ‘0R…
Tag: sql
How to use variables in “EXECUTE format()” in plpgsql
I want to update a column in table stats with the specific column being a parameter, then return the updated value of that column [only has 1 row]: CREATE FUNCTION grow(col varchar) RETURNS integer …
MS SQL Server – How to create a view from a CTE?
The here above SQL is outputing like a charm all hours between two dates and a field retrieved from a join with another table: I would like to create a view from that but I do not manage to do it. I tried several things but without success. The following is returning : Incorrect syntax near the keyword ‘…
MySQL query to get “intersection” of numerous queries with limits
Assume I have a single mySQL table (users) with the following fields: I want to be able to return the number of total records based on the number a user enters. Furthermore, they will also be providing additional criteria. In the simplest example, they may ask for 1,000 records, where 600 records should have …
Laravel – Add custom column in select with Eloquent query buider
this is a simplified use case, only to illustrate what I want to achieve: Considering this query in pure SQL: How can I add the constant active column using query builder ? Here is my Query Builder without the extra column: Answer Simplest would be to use DB::raw
Aggregate columns with additional (distinct) filters
This code works as expected, but I it’s long and creepy. As you can see, it consists of 3 repetitive parts for retrieving: player name and the amount of games they played player name and the amount of games they won player name and the amount of games they lost And each of those also consists of 2 parts…
SQL select when one condition or another are met but not both
Given the following table: what is the nicest way to query selecting rows when number 4 and 14 are selected in column1 or column2 BUT exclude when number 4 and number 14 are both in the row. Be aware that the order can be reversed. expected output Answer
Get previous and next row from rows selected with (WHERE) conditions
For example I have this statement: This statement is splitted by word, like this table: I want to get previous and next word of each word For example I want to get previous and next word of “name”: How could I get this result? Answer you didn’t specify your DBMS, so the following is ANSI SQL…
How to enable logging for SQL statements when using JDBC
I am trying to enable logs using my JDBC program by connecting to Oracle database in eclipse IDE. I have gone through this SO post JDBC logging to file then I have created below java program and running it from my eclipse IDE, but I was not able to see any logs generated by the JDBC driver classes. and I
which gives best performance?
Please go through the following query, and help me to understand which one is efficient and how? In logical query execution, where clause will be executed after completion of join, so I thought the …