How to use MIN() function of postgresql using java code - spring

I need to find the minimum value from a table . How to use that using java.
databaseClient.sql("Select MIN (employee_salary) " +
"from " + schema + ".employee_instances where employee_id =:employeeId")
This gives me error when i execute my code -
ERROR-
"Column name 'employee_salary' does not exist in column names [min]",

#a_horse_with_no_name's comment above helped resolve my problem:
it seems your Java code tries to retrieve a column named employee_salary but your query does not have such a column (only a column named min). You will need a column alias if that is the case: min(employee_salary) as employee_salary

Related

MS ACCESS table default value code line for autogenerated sequential and unique alphanumeric number

I am new to MS Access and I would like to generate an autogenerated sequential and unique alphanumeric number of the format SYYMM001, SYYMM002, SYYMM003... (ex for 2023 january: S2301001, S2301002, S2301003).
I use MS Access 2016.
I am in my table, in View mode, in the column InvoiceCode in which I want the number to appear, in the general sheet, in Default Value I used the following code:
= "S" & Format(Now(),"yymm") & Format((DCount("[InvoiceID]","InvoiceTable")),"000")
where InvoiceID is the autonumber column and InvoiceTable the name of the table.
This code does not work and generate the following error:
"Unknown function "Dcount" in validation expression or default value on "Invoice Table.InvoiceCode"
I tried another code that I found online which works but instead of giving me a sequential number it generate a random number ex S2301586, S2301236 ...
="S" & Format(Now(),"yymm") & Format(Int(Rnd()*1000),"000")
Would you have a code that would do what I need?
Thanks in advance for your help
You can't set this in the table.
You could try this in your form you use for data entry - in the BeforeInsert event of the form:
Me!InvoiceID.Value = "S" & Format(Date,"yymm") & Format(DCount("*","InvoiceTable"),"000")

New column indicating if row is the first instance of the value for the Entity ID using SQL instead of DAX

I currently have a column that is created using the following DAX formula (a calculating language used by platforms such as Power BI) which indicates if the listed activity is the first one ever for that Entity ID. Below is my DAX script if it helps at all:
// "Declares column name"
First Time Activity =
// "if the column 'Timestamp' is equal to..."
if('Activity Table'[Timestamp]=
// "...is equal to the earliest Timestamp for that Entity ID and Activity Name"
CALCULATE(min('Activity Table'[Timestamp]),
filter('Activity Table',
'Activity Table'[Entity ID] = earlier('Activity Table'[Entity ID]) &&
'Activity Table'[Activity Name] = earlier('Activity Table'[Activity Name])
)
)
// "...then return a 1. If not, then return a blank/null"
,1,BLANK())
But I need this now to be a column made in PL SQL rather than in DAX. Any help on the SQL script would be much appreciated since I'm fairly novice at SQL.
Thanks
You don't actually need a column. you can write your query as :
Select a
,decode(activity_date
,MIN(activity_date) over (partition by activity_id)
,'Y'
,'N') first_record_indicator
From activity_table a
But, if you table is too huge to actually query like this everytime, you can create a column named first_record_indicator and populate it in "BEFORE INSERT" trigger.
e.g. https://www.techonthenet.com/oracle/triggers/before_insert.php

codeigniter update issue You have an error in your SQL syntax

I am getting the error when I am updating
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0 = Array WHERE order_id = '11'' at line 1
UPDATE rel_orders_prices SET 0 = Array WHERE order_id = '11'
Filename: modules/admin/models/Booking_model.php
Line Number: 241
You should use backticks for the column name, because it contains only numbers and the value should be within quotes, so this should work:
UPDATE rel_orders_prices SET `0` = 'Array' WHERE order_id = '11'
Identifiers may begin with a digit but unless quoted may not consist solely of digits.
From: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
try this query in your model file.
function update($order_id,$insertArray){
return $this->db->where('order_id', $order_id)->update('tablename',$insertArray);
}
Use this like,
$this->db->set('save_price',$save_price);
Because column name missing.
If array then,
$this->db->set(array('save_price'=>$save_price));
OR
$this->db->update('rel_orders_prices',array('save_price'=>$save_price));

ORACLE detecting duplicate data even the text is lower or uppercase

I'm using ORACLE database. How to detect duplicate data even the text is lower or uppercase.
Assuming on my table already inserted : Production
Now I want to add: production (with lower case), it should be detect duplicate. In my current case, it was not detected and inserted.
Here is the sample query:
SELECT * FROM tb_departments WHERE DEPARTMENT_NAME = '" . $getDepartmentName . "';
Anyone have an idea?
You can use the UPPER (or LOWER) function, which capitalize your string, i.e.
SELECT * FROM tb_departments WHERE UPPER(DEPARTMENT_NAME) = UPPER('" . $getDepartmentName . "');
As small variation you could capitalize your input string in the code and use
SELECT * FROM tb_departments WHERE UPPER(DEPARTMENT_NAME) = '" . $yourUpperDepartmentName . "';
Moreover I suggest you use query parameters, instead of injecting directly the parameters string ($getDepartmentName ) in your query.

Propel, selecting just one column

I am trying to run a query in propel that runs an aggregate function (SUM).
My Code
$itemQuery = SomeEntity::Create();
$itemQuery->withColumn('SUM(SomeColumn)', someColumn)
->groupBy(SomeForeignKey);
Problem
It should theoretically return the sum of every group of items but the problem is propel tries to fetch all columns, and also appends a bunch of other columns to the group by clause. This results in an unexpected categorisation and therefore the sum is incorrect.
Is there anyway to make propel fetch just the column I am running the aggregation function on so that the group by statement works as well?
You need to add a select statement for the column and the foreign key:
$itemQuery = SomeEntity::Create();
$itemQuery->select(array(SomeColumn, SomeForeignKey));
$itemQuery->withColumn('SUM(SomeColumn)', someColumn);
$itemQuery->groupBy(SomeForeignKey);

Resources