calculate profit 10% from buy price - mysql

I have this script calculates profit
Steps :
barangbeli = harsat / diameter
p1 = barangbeli * 10
p2 = prof / 100
result = barangbeli + profit;
thanks
CREATE VIEW tbkeluar as
SELECT mbarang.kdbrg, mbarang.nmbrg, mbarang.spek,if(SUM(bkeluar.qty), SUM(bkeluar.qty), 0)as qty,(tbmasuk.harsat/mbarang.diameter) as hargabeli, ((hargabeli*10)/100 )+hargabeli) as profit
LEFT JOIN bkeluar on mbarang.kdbrg = bkeluar.kdbrg group by mbarang.kdbrg
i have error
#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 ') as profit from mbarang
LEFT JOIN bkeluar on mbarang.kdbrg = bkeluar.kdbrg gro' at line 2

The error message you received should be helpful enough to know whats wrong.
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 ') as profit from mbarang LEFT JOIN bkeluar on mbarang.kdbrg = bkeluar.kdbrg gro' at line 2
Based from the error message, MySQL says that you have a syntax error because of this character ), with some characters appended for you to locate it: ) as profit from mbarang
As you can see from your SELECT statement, you have an extra )
SELECT mbarang.kdbrg
, mbarang.nmbrg
, mbarang.spek
,if(SUM(bkeluar.qty), SUM(bkeluar.qty), 0)as qty
,(tbmasuk.harsat/mbarang.diameter) as hargabeli
, ((hargabeli*10)/100 )+hargabeli) as profit
^ delete this extra parenthesis

Your SELECT statement (in CREATE VIEW) is missing its FROM clause. Do you mean FROM mbarang?
You're also probably missing at least one more JOIN; the table tbmasuk is mentioned in the SELECT clause, but isn't mentioned anywhere else in the statement.

Related

Where is my mistake selecting coalesce mysql?

I have a column discount_amount, if there's no SUM(discount_amount) (NULL) THEN it's zero (0).
I wrote the query with this
SELECT COALESCE(SUM(discount_amount)
FROM order_discount
WHERE order_discount.discount_type_id = 6
AND order_discount.order_match_id = om1.id, 0);
but I get an error
Error Code: 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 'FROM order_discount WHERE order_discount.discou' at line 2
You seem to want:
SELECT COALESCE(SUM(discount_amount), 0)
FROM order_discount
WHERE order_discount.discount_type_id = 6 AND order_discount.order_match_id = om1.id;
This has to be part of bigger query, where derive table om1 is defined somehow.
Alternatively, you can COALESCE() the result of the subquery like this:
COALESCE(
(
SELECT SUM(discount_amount)
FROM order_discount
WHERE order_discount.discount_type_id = 6 AND order_discount.order_match_id = om1.id
),
0
)
Again, this only makes sense if included in a bigger query.

1064 You have an error in your SQL syntax; - shows in my website

I was working on my new joomla website changed some appearing sittings then the syntax error came out in the main page and changed all the website design I tried to undo all the changes I made and the error still there
the message I got
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 ') AND c.access_view IN (0,1,1,5) AND c.restriction_18=0 ORDER BY
i.date_start D' at line 2
SELECT i.*,c.id as c_id, c.name as c_name,c.alias as c_alias,c.icon_url as c_icon_url,
r.name as r_name, img.path as img_path, img.name as img_name, img.ext as img_ext,
img.caption as img_caption
FROM l0ucm_djcf_categories c, l0ucm_djcf_items i
LEFT JOIN l0ucm_djcf_regions r ON r.id=i.region_id
LEFT JOIN ( SELECT img.id, img.item_id, img.name, img.path, img.ext, img.ordering, img.caption
FROM (SELECT * FROM l0ucm_djcf_images WHERE type='item' ORDER BY ordering) img GROUP BY img.item_id ) AS img
ON img.item_id=i.id
WHERE i.date_exp > '2015-07-25 16:44:45' AND i.published = 1 AND c.published = 1
AND i.cat_id=c.id AND i.cat_id IN (9,10,11,12,13,15)
AND i.type_id IN () AND c.access_view IN (0,1,1,5) AND c.restriction_18=0
ORDER BY i.date_start DESC limit 9
anyone can help me to find out from where I can solve this problem?
thank you all,
The problem is in the statement AND i.type_id IN ().
IN() function cannot get an empty value. You should check the php code that creates the query and add a validation to the variable to add the statement only if it not empty.

SQL query: join two tables

so i get an error on the this sql query, but i canĀ“t see my mistake myself:
SELECT group_members.group_id,
group_members.permissions,
group.group_name
FROM group_members,
group
WHERE group_members.group_id=group.group_id
AND group.group_id = 1
Error:
#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 'group WHERE group_members.group_id=group.group_id AND group.group_id = 1
Thanks for your help!
Group is a reserved word in MySQL either enclose it in backticks "`" or better yet do not use it as a table name
SELECT group_members.group_id, group_members.permissions, `group`.group_name
FROM group_members, `group`
WHERE group_members.group_id=`group`.group_id
AND `group`.group_id = 1
Try this
SELECT group_members.group_id, group_members.permissions, `group`.group_name
FROM group_members, group
WHERE group_members.group_id=`group`.group_id
AND `group`.group_id = 1

#1064 - You have an error in your SQL syntax when creating a View

Could someone please tell me what's wrong with this code that's making it spit back an error?
My code is as follows:
CREATE OR REPLACE VIEW vw_training AS
SELECT training.train_attended, clients.client_firstname, clients.client_lastname, clients.client_swn, clients.client_id, locations.loc_id, locations.loc_title, locationsp.loc_id, locationsp.loc_title,
FROM training
JOIN clients ON clients.client_id = training.train_clientid
JOIN locations AS locationsp ON locations.loc_id = training.train_pickup
LEFT JOIN locations ON locations.loc_id = clients.client_winz
And this is the error I'm getting back:
#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 'FROM training JOIN clients ON clients.client_id =
training.train_clientid JOIN' at line 3
I'm running phpmyadmin Version information: 3.5.2.2
I've used this script with different values before with no issues
You have an extra trailing comma before the FROM clause
SELECT ....,
locationsp.loc_id,
locationsp.loc_title, -- <<== remove this trailing comma
FROM training ...
and another error that will raise this message: Unknown column 'locations.loc_id' in 'on clause' is the use of tablename and not the alias supplied. it should be,
JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
^^ should use alias here

MySQL Error "right syntax to use near '/*100,3), '%') AS `Percentage` FROM INFORMATION_SCHEMA.PROFILING"

I got this weird error after trying to execute a query on a large table:
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 '/*100,3),
'%') AS Percentage FROM
INFORMATION_SCHEMA.PROFILING WHERE
QUERY_ID=' at line 1
What does it mean?
EDIT == this is the query
update cities w, states s set w.region_id = s.id
where s.code = w.region and w.country_id = s.country_id
The cities table has around 3 million entries and the states table around 6000
Just for the record I executed this query using a mysql client Navicat.
SQL supports C-style comments:
/* ... */
so it looks like /*100,3 is being interpreted as the beginning of a comment and that comment is wrecking the syntax of the rest of the SQL.