I wrote the following query What is wrong with this? Answer If you want it to work with lower/upper letters, you could use UPPER(CITY), otherwise it’s all good.
Tag: sql
RETURNING rows using unnest()?
I’m trying to return a set of rows after doing UPDATE. Something like this. but postgres complains, rightly so: set-valued function called in context that cannot accept a set How am I supposed to go about implementing this? That is, RETURNING a set of rows from SELECTed array after UPDATE? I’m awa…
Count rows after joining three tables in PostgreSQL
Suppose I have three tables in PostgreSQL: Suppose I am using the using the following query: I get 50 as count. Whereas with: I get only 25 as count. What is my mistake in the second query? What can I do to get the same count? My requirement is that there is a single user table, referenced by multiple tables.
How to calculate power consumption from power records?
I have table which contains power values (kW) for devices. Values are read from each device once a minute and inserted into table with timestamp. What I need to do is calculate power consumption (kWh) for given time span and return 10 most power consuming devices. Right now I query results for given time span…
SQL Server – group by with row number – Gaps and Islands
I have a table with data like this I need to create a view on top of this table to have data formatted in the below format for the Flag, basically the duration for which the Flag was Y or N. (EndDateSID – 0 is currently active, so today’s date) Most customers only have a change in their Flag once,
increment value in mysql after the table has been created
I would like to change the value in the second column to increment and also change the current NULL values to start using that incrementing system that begins at a value other than 1. I do see I can …
SELECT if 2 cells in a row are equal
Tried to show it as simple as possible. I want to SELECT Subject if 2 cells in a row are equal Table Result I need is to select subject C cause username and lastpostername are equal (Sorted DESC by ID, so newest comes first) Answer
@SET (SQL) in PHP
How to state SET @unix_four_weeks_ago = UNIX_TIMESTAMP(curdate()) – 2419200; in php file. SQL PHP The query is all about getting the last 4weeks records. The query was working fine in SQL, but not giving any output when I run php file. Answer As the others already said, multi_query will allow you to run…
How to send plain SQL queries (and retrieve results) using scala slick 3
I am trying to make a class that has methods that can send and get data to an SQLite db using plain sql queries. This unfortunately does not work. I do not want to use the withSession implicit parts. The following error is thrown: type mismatch; found : slick.profile.SqlStreamingAction[Vector[(Int, Double, St…
How to add and subtract value from previous rows based on condition
I have a table with values Slno Type Amount 1 P 40 2 C 20 3 P 45 4 P 20 5 C 10 …